home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gcc_260.zip / gcc_260 / tree.c < prev    next >
C/C++ Source or Header  |  1994-07-14  |  111KB  |  3,997 lines

  1. /* Language-independent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the low level primitives for operating on tree nodes,
  22.    including allocation, list operations, interning of identifiers,
  23.    construction of data type nodes and statement nodes,
  24.    and construction of type conversion nodes.  It also contains
  25.    tables index by tree code that describe how to take apart
  26.    nodes of that code.
  27.  
  28.    It is intended to be language-independent, but occasionally
  29.    calls language-dependent routines defined (for C) in typecheck.c.
  30.  
  31.    The low-level allocation routines oballoc and permalloc
  32.    are used also for allocating many other kinds of objects
  33.    by all passes of the compiler.  */
  34.  
  35. #include <setjmp.h>
  36. #include "config.h"
  37. #include "flags.h"
  38. #include "tree.h"
  39. #include "function.h"
  40. #include "obstack.h"
  41. #ifdef __STDC__
  42. #include <stdarg.h>
  43. #else
  44. #include <varargs.h>
  45. #endif
  46. #include <stdio.h>
  47.  
  48. #define obstack_chunk_alloc xmalloc
  49. #define obstack_chunk_free free
  50.  
  51. /* Tree nodes of permanent duration are allocated in this obstack.
  52.    They are the identifier nodes, and everything outside of
  53.    the bodies and parameters of function definitions.  */
  54.  
  55. struct obstack permanent_obstack;
  56.  
  57. /* The initial RTL, and all ..._TYPE nodes, in a function
  58.    are allocated in this obstack.  Usually they are freed at the
  59.    end of the function, but if the function is inline they are saved.
  60.    For top-level functions, this is maybepermanent_obstack.
  61.    Separate obstacks are made for nested functions.  */
  62.  
  63. struct obstack *function_maybepermanent_obstack;
  64.  
  65. /* This is the function_maybepermanent_obstack for top-level functions.  */
  66.  
  67. struct obstack maybepermanent_obstack;
  68.  
  69. /* The contents of the current function definition are allocated
  70.    in this obstack, and all are freed at the end of the function.
  71.    For top-level functions, this is temporary_obstack.
  72.    Separate obstacks are made for nested functions.  */
  73.  
  74. struct obstack *function_obstack;
  75.  
  76. /* This is used for reading initializers of global variables.  */
  77.  
  78. struct obstack temporary_obstack;
  79.  
  80. /* The tree nodes of an expression are allocated
  81.    in this obstack, and all are freed at the end of the expression.  */
  82.  
  83. struct obstack momentary_obstack;
  84.  
  85. /* The tree nodes of a declarator are allocated
  86.    in this obstack, and all are freed when the declarator
  87.    has been parsed.  */
  88.  
  89. static struct obstack temp_decl_obstack;
  90.  
  91. /* This points at either permanent_obstack
  92.    or the current function_maybepermanent_obstack.  */
  93.  
  94. struct obstack *saveable_obstack;
  95.  
  96. /* This is same as saveable_obstack during parse and expansion phase;
  97.    it points to the current function's obstack during optimization.
  98.    This is the obstack to be used for creating rtl objects.  */
  99.  
  100. struct obstack *rtl_obstack;
  101.  
  102. /* This points at either permanent_obstack or the current function_obstack.  */
  103.  
  104. struct obstack *current_obstack;
  105.  
  106. /* This points at either permanent_obstack or the current function_obstack
  107.    or momentary_obstack.  */
  108.  
  109. struct obstack *expression_obstack;
  110.  
  111. /* Stack of obstack selections for push_obstacks and pop_obstacks.  */
  112.  
  113. struct obstack_stack
  114. {
  115.   struct obstack_stack *next;
  116.   struct obstack *current;
  117.   struct obstack *saveable;
  118.   struct obstack *expression;
  119.   struct obstack *rtl;
  120. };
  121.  
  122. struct obstack_stack *obstack_stack;
  123.  
  124. /* Obstack for allocating struct obstack_stack entries.  */
  125.  
  126. static struct obstack obstack_stack_obstack;
  127.  
  128. /* Addresses of first objects in some obstacks.
  129.    This is for freeing their entire contents.  */
  130. char *maybepermanent_firstobj;
  131. char *temporary_firstobj;
  132. char *momentary_firstobj;
  133. char *temp_decl_firstobj;
  134.  
  135. /* This is used to preserve objects (mainly array initializers) that need to
  136.    live until the end of the current function, but no further.  */
  137. char *momentary_function_firstobj;
  138.  
  139. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  140.  
  141. int all_types_permanent;
  142.  
  143. /* Stack of places to restore the momentary obstack back to.  */
  144.    
  145. struct momentary_level
  146. {
  147.   /* Pointer back to previous such level.  */
  148.   struct momentary_level *prev;
  149.   /* First object allocated within this level.  */
  150.   char *base;
  151.   /* Value of expression_obstack saved at entry to this level.  */
  152.   struct obstack *obstack;
  153. };
  154.  
  155. struct momentary_level *momentary_stack;
  156.  
  157. /* Table indexed by tree code giving a string containing a character
  158.    classifying the tree code.  Possibilities are
  159.    t, d, s, c, r, <, 1, 2 and e.  See tree.def for details.  */
  160.  
  161. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  162.  
  163. char *standard_tree_code_type[] = {
  164. #include "tree.def"
  165. };
  166. #undef DEFTREECODE
  167.  
  168. /* Table indexed by tree code giving number of expression
  169.    operands beyond the fixed part of the node structure.
  170.    Not used for types or decls.  */
  171.  
  172. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  173.  
  174. int standard_tree_code_length[] = {
  175. #include "tree.def"
  176. };
  177. #undef DEFTREECODE
  178.  
  179. /* Names of tree components.
  180.    Used for printing out the tree and error messages.  */
  181. #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  182.  
  183. char *standard_tree_code_name[] = {
  184. #include "tree.def"
  185. };
  186. #undef DEFTREECODE
  187.  
  188. /* Table indexed by tree code giving a string containing a character
  189.    classifying the tree code.  Possibilities are
  190.    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
  191.  
  192. char **tree_code_type;
  193.  
  194. /* Table indexed by tree code giving number of expression
  195.    operands beyond the fixed part of the node structure.
  196.    Not used for types or decls.  */
  197.  
  198. int *tree_code_length;
  199.  
  200. /* Table indexed by tree code giving name of tree code, as a string.  */
  201.  
  202. char **tree_code_name;
  203.  
  204. /* Statistics-gathering stuff.  */
  205. typedef enum
  206. {
  207.   d_kind,
  208.   t_kind,
  209.   b_kind,
  210.   s_kind,
  211.   r_kind,
  212.   e_kind,
  213.   c_kind,
  214.   id_kind,
  215.   op_id_kind,
  216.   perm_list_kind,
  217.   temp_list_kind,
  218.   vec_kind,
  219.   x_kind,
  220.   lang_decl,
  221.   lang_type,
  222.   all_kinds
  223. } tree_node_kind;
  224.  
  225. int tree_node_counts[(int)all_kinds];
  226. int tree_node_sizes[(int)all_kinds];
  227. int id_string_size = 0;
  228.  
  229. char *tree_node_kind_names[] = {
  230.   "decls",
  231.   "types",
  232.   "blocks",
  233.   "stmts",
  234.   "refs",
  235.   "exprs",
  236.   "constants",
  237.   "identifiers",
  238.   "op_identifiers",
  239.   "perm_tree_lists",
  240.   "temp_tree_lists",
  241.   "vecs",
  242.   "random kinds",
  243.   "lang_decl kinds",
  244.   "lang_type kinds"
  245. };
  246.  
  247. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  248.  
  249. #define MAX_HASH_TABLE 1009
  250. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  251.  
  252. /* 0 while creating built-in identifiers.  */
  253. static int do_identifier_warnings;
  254.  
  255. /* Unique id for next decl created.  */
  256. static int next_decl_uid;
  257. /* Unique id for next type created.  */
  258. static int next_type_uid = 1;
  259.  
  260. /* Here is how primitive or already-canonicalized types' hash
  261.    codes are made.  */
  262. #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
  263.  
  264. extern char *mode_name[];
  265.  
  266. void gcc_obstack_init ();
  267. static tree stabilize_reference_1 ();
  268.  
  269. /* Init the principal obstacks.  */
  270.  
  271. void
  272. init_obstacks ()
  273. {
  274.   gcc_obstack_init (&obstack_stack_obstack);
  275.   gcc_obstack_init (&permanent_obstack);
  276.  
  277.   gcc_obstack_init (&temporary_obstack);
  278.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  279.   gcc_obstack_init (&momentary_obstack);
  280.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  281.   momentary_function_firstobj = momentary_firstobj;
  282.   gcc_obstack_init (&maybepermanent_obstack);
  283.   maybepermanent_firstobj
  284.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  285.   gcc_obstack_init (&temp_decl_obstack);
  286.   temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
  287.  
  288.   function_obstack = &temporary_obstack;
  289.   function_maybepermanent_obstack = &maybepermanent_obstack;
  290.   current_obstack = &permanent_obstack;
  291.   expression_obstack = &permanent_obstack;
  292.   rtl_obstack = saveable_obstack = &permanent_obstack;
  293.  
  294.   /* Init the hash table of identifiers.  */
  295.   bzero ((char *) hash_table, sizeof hash_table);
  296. }
  297.  
  298. void
  299. gcc_obstack_init (obstack)
  300.      struct obstack *obstack;
  301. {
  302.   /* Let particular systems override the size of a chunk.  */
  303. #ifndef OBSTACK_CHUNK_SIZE
  304. #define OBSTACK_CHUNK_SIZE 0
  305. #endif
  306.   /* Let them override the alloc and free routines too.  */
  307. #ifndef OBSTACK_CHUNK_ALLOC
  308. #define OBSTACK_CHUNK_ALLOC xmalloc
  309. #endif
  310. #ifndef OBSTACK_CHUNK_FREE
  311. #define OBSTACK_CHUNK_FREE free
  312. #endif
  313.   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
  314.           (void *(*) ()) OBSTACK_CHUNK_ALLOC,
  315.           (void (*) ()) OBSTACK_CHUNK_FREE);
  316. }
  317.  
  318. /* Save all variables describing the current status into the structure *P.
  319.    This is used before starting a nested function.  */
  320.  
  321. void
  322. save_tree_status (p)
  323.      struct function *p;
  324. {
  325.   p->all_types_permanent = all_types_permanent;
  326.   p->momentary_stack = momentary_stack;
  327.   p->maybepermanent_firstobj = maybepermanent_firstobj;
  328.   p->momentary_firstobj = momentary_firstobj;
  329.   p->momentary_function_firstobj = momentary_function_firstobj;
  330.   p->function_obstack = function_obstack;
  331.   p->function_maybepermanent_obstack = function_maybepermanent_obstack;
  332.   p->current_obstack = current_obstack;
  333.   p->expression_obstack = expression_obstack;
  334.   p->saveable_obstack = saveable_obstack;
  335.   p->rtl_obstack = rtl_obstack;
  336.  
  337.   /* Objects that need to be saved in this function can be in the nonsaved
  338.      obstack of the enclosing function since they can't possibly be needed
  339.      once it has returned.  */
  340.   function_maybepermanent_obstack = function_obstack;
  341.  
  342.   function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  343.   gcc_obstack_init (function_obstack);
  344.  
  345.   current_obstack = &permanent_obstack;
  346.   expression_obstack = &permanent_obstack;
  347.   rtl_obstack = saveable_obstack = &permanent_obstack;
  348.  
  349.   momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
  350.   momentary_function_firstobj = momentary_firstobj;
  351.   maybepermanent_firstobj
  352.     = (char *) obstack_finish (function_maybepermanent_obstack);
  353. }
  354.  
  355. /* Restore all variables describing the current status from the structure *P.
  356.    This is used after a nested function.  */
  357.  
  358. void
  359. restore_tree_status (p)
  360.      struct function *p;
  361. {
  362.   all_types_permanent = p->all_types_permanent;
  363.   momentary_stack = p->momentary_stack;
  364.  
  365.   obstack_free (&momentary_obstack, momentary_function_firstobj);
  366.  
  367.   /* Free saveable storage used by the function just compiled and not
  368.      saved.
  369.  
  370.      CAUTION: This is in function_obstack of the containing function.  So
  371.      we must be sure that we never allocate from that obstack during
  372.      the compilation of a nested function if we expect it to survive past the
  373.      nested function's end.  */
  374.   obstack_free (function_maybepermanent_obstack, maybepermanent_firstobj);
  375.  
  376.   obstack_free (function_obstack, 0);
  377.   free (function_obstack);
  378.  
  379.   momentary_firstobj = p->momentary_firstobj;
  380.   momentary_function_firstobj = p->momentary_function_firstobj;
  381.   maybepermanent_firstobj = p->maybepermanent_firstobj;
  382.   function_obstack = p->function_obstack;
  383.   function_maybepermanent_obstack = p->function_maybepermanent_obstack;
  384.   current_obstack = p->current_obstack;
  385.   expression_obstack = p->expression_obstack;
  386.   saveable_obstack = p->saveable_obstack;
  387.   rtl_obstack = p->rtl_obstack;
  388. }
  389.  
  390. /* Start allocating on the temporary (per function) obstack.
  391.    This is done in start_function before parsing the function body,
  392.    and before each initialization at top level, and to go back
  393.    to temporary allocation after doing permanent_allocation.  */
  394.  
  395. void
  396. temporary_allocation ()
  397. {
  398.   /* Note that function_obstack at top level points to temporary_obstack.
  399.      But within a nested function context, it is a separate obstack.  */
  400.   current_obstack = function_obstack;
  401.   expression_obstack = function_obstack;
  402.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  403.   momentary_stack = 0;
  404. }
  405.  
  406. /* Start allocating on the permanent obstack but don't
  407.    free the temporary data.  After calling this, call
  408.    `permanent_allocation' to fully resume permanent allocation status.  */
  409.  
  410. void
  411. end_temporary_allocation ()
  412. {
  413.   current_obstack = &permanent_obstack;
  414.   expression_obstack = &permanent_obstack;
  415.   rtl_obstack = saveable_obstack = &permanent_obstack;
  416. }
  417.  
  418. /* Resume allocating on the temporary obstack, undoing
  419.    effects of `end_temporary_allocation'.  */
  420.  
  421. void
  422. resume_temporary_allocation ()
  423. {
  424.   current_obstack = function_obstack;
  425.   expression_obstack = function_obstack;
  426.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  427. }
  428.  
  429. /* While doing temporary allocation, switch to allocating in such a
  430.    way as to save all nodes if the function is inlined.  Call
  431.    resume_temporary_allocation to go back to ordinary temporary
  432.    allocation.  */
  433.  
  434. void
  435. saveable_allocation ()
  436. {
  437.   /* Note that function_obstack at top level points to temporary_obstack.
  438.      But within a nested function context, it is a separate obstack.  */
  439.   expression_obstack = current_obstack = saveable_obstack;
  440. }
  441.  
  442. /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
  443.    recording the previously current obstacks on a stack.
  444.    This does not free any storage in any obstack.  */
  445.  
  446. void
  447. push_obstacks (current, saveable)
  448.      struct obstack *current, *saveable;
  449. {
  450.   struct obstack_stack *p
  451.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  452.                           (sizeof (struct obstack_stack)));
  453.  
  454.   p->current = current_obstack;
  455.   p->saveable = saveable_obstack;
  456.   p->expression = expression_obstack;
  457.   p->rtl = rtl_obstack;
  458.   p->next = obstack_stack;
  459.   obstack_stack = p;
  460.  
  461.   current_obstack = current;
  462.   expression_obstack = current;
  463.   rtl_obstack = saveable_obstack = saveable;
  464. }
  465.  
  466. /* Save the current set of obstacks, but don't change them.  */
  467.  
  468. void
  469. push_obstacks_nochange ()
  470. {
  471.   struct obstack_stack *p
  472.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  473.                           (sizeof (struct obstack_stack)));
  474.  
  475.   p->current = current_obstack;
  476.   p->saveable = saveable_obstack;
  477.   p->expression = expression_obstack;
  478.   p->rtl = rtl_obstack;
  479.   p->next = obstack_stack;
  480.   obstack_stack = p;
  481. }
  482.  
  483. /* Pop the obstack selection stack.  */
  484.  
  485. void
  486. pop_obstacks ()
  487. {
  488.   struct obstack_stack *p = obstack_stack;
  489.   obstack_stack = p->next;
  490.  
  491.   current_obstack = p->current;
  492.   saveable_obstack = p->saveable;
  493.   expression_obstack = p->expression;
  494.   rtl_obstack = p->rtl;
  495.  
  496.   obstack_free (&obstack_stack_obstack, p);
  497. }
  498.  
  499. /* Nonzero if temporary allocation is currently in effect.
  500.    Zero if currently doing permanent allocation.  */
  501.  
  502. int
  503. allocation_temporary_p ()
  504. {
  505.   return current_obstack != &permanent_obstack;
  506. }
  507.  
  508. /* Go back to allocating on the permanent obstack
  509.    and free everything in the temporary obstack.
  510.  
  511.    FUNCTION_END is true only if we have just finished compiling a function.
  512.    In that case, we also free preserved initial values on the momentary
  513.    obstack.  */
  514.  
  515. void
  516. permanent_allocation (function_end)
  517.      int function_end;
  518. {
  519.   /* Free up previous temporary obstack data */
  520.   obstack_free (&temporary_obstack, temporary_firstobj);
  521.   if (function_end)
  522.     obstack_free (&momentary_obstack, momentary_function_firstobj);
  523.   else
  524.     obstack_free (&momentary_obstack, momentary_firstobj);
  525.   obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
  526.   obstack_free (&temp_decl_obstack, temp_decl_firstobj);
  527.  
  528.   current_obstack = &permanent_obstack;
  529.   expression_obstack = &permanent_obstack;
  530.   rtl_obstack = saveable_obstack = &permanent_obstack;
  531. }
  532.  
  533. /* Save permanently everything on the maybepermanent_obstack.  */
  534.  
  535. void
  536. preserve_data ()
  537. {
  538.   maybepermanent_firstobj
  539.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  540. }
  541.  
  542. void
  543. preserve_initializer ()
  544. {
  545.   struct momentary_level *tem;
  546.   char *old_momentary;
  547.  
  548.   temporary_firstobj
  549.     = (char *) obstack_alloc (&temporary_obstack, 0);
  550.   maybepermanent_firstobj
  551.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  552.  
  553.   old_momentary = momentary_firstobj;
  554.   momentary_firstobj
  555.     = (char *) obstack_alloc (&momentary_obstack, 0);
  556.   if (momentary_firstobj != old_momentary)
  557.     for (tem = momentary_stack; tem; tem = tem->prev)
  558.       tem->base = momentary_firstobj;
  559. }
  560.  
  561. /* Start allocating new rtl in current_obstack.
  562.    Use resume_temporary_allocation
  563.    to go back to allocating rtl in saveable_obstack.  */
  564.  
  565. void
  566. rtl_in_current_obstack ()
  567. {
  568.   rtl_obstack = current_obstack;
  569. }
  570.  
  571. /* Start allocating rtl from saveable_obstack.  Intended to be used after
  572.    a call to push_obstacks_nochange.  */
  573.  
  574. void
  575. rtl_in_saveable_obstack ()
  576. {
  577.   rtl_obstack = saveable_obstack;
  578. }
  579.  
  580. /* Allocate SIZE bytes in the current obstack
  581.    and return a pointer to them.
  582.    In practice the current obstack is always the temporary one.  */
  583.  
  584. char *
  585. oballoc (size)
  586.      int size;
  587. {
  588.   return (char *) obstack_alloc (current_obstack, size);
  589. }
  590.  
  591. /* Free the object PTR in the current obstack
  592.    as well as everything allocated since PTR.
  593.    In practice the current obstack is always the temporary one.  */
  594.  
  595. void
  596. obfree (ptr)
  597.      char *ptr;
  598. {
  599.   obstack_free (current_obstack, ptr);
  600. }
  601.  
  602. /* Allocate SIZE bytes in the permanent obstack
  603.    and return a pointer to them.  */
  604.  
  605. char *
  606. permalloc (size)
  607.      int size;
  608. {
  609.   return (char *) obstack_alloc (&permanent_obstack, size);
  610. }
  611.  
  612. /* Allocate NELEM items of SIZE bytes in the permanent obstack
  613.    and return a pointer to them.  The storage is cleared before
  614.    returning the value.  */
  615.  
  616. char *
  617. perm_calloc (nelem, size)
  618.      int nelem;
  619.      long size;
  620. {
  621.   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
  622.   bzero (rval, nelem * size);
  623.   return rval;
  624. }
  625.  
  626. /* Allocate SIZE bytes in the saveable obstack
  627.    and return a pointer to them.  */
  628.  
  629. char *
  630. savealloc (size)
  631.      int size;
  632. {
  633.   return (char *) obstack_alloc (saveable_obstack, size);
  634. }
  635.  
  636. /* Print out which obstack an object is in.  */
  637.  
  638. void
  639. print_obstack_name (object, file, prefix)
  640.      char *object;
  641.      FILE *file;
  642.      char *prefix;
  643. {
  644.   struct obstack *obstack = NULL;
  645.   char *obstack_name = NULL;
  646.   struct function *p;
  647.  
  648.   for (p = outer_function_chain; p; p = p->next)
  649.     {
  650.       if (_obstack_allocated_p (p->function_obstack, object))
  651.     {
  652.       obstack = p->function_obstack;
  653.       obstack_name = "containing function obstack";
  654.     }
  655.       if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
  656.     {
  657.       obstack = p->function_maybepermanent_obstack;
  658.       obstack_name = "containing function maybepermanent obstack";
  659.     }
  660.     }
  661.  
  662.   if (_obstack_allocated_p (&obstack_stack_obstack, object))
  663.     {
  664.       obstack = &obstack_stack_obstack;
  665.       obstack_name = "obstack_stack_obstack";
  666.     }
  667.   else if (_obstack_allocated_p (function_obstack, object))
  668.     {
  669.       obstack = function_obstack;
  670.       obstack_name = "function obstack";
  671.     }
  672.   else if (_obstack_allocated_p (&permanent_obstack, object))
  673.     {
  674.       obstack = &permanent_obstack;
  675.       obstack_name = "permanent_obstack";
  676.     }
  677.   else if (_obstack_allocated_p (&momentary_obstack, object))
  678.     {
  679.       obstack = &momentary_obstack;
  680.       obstack_name = "momentary_obstack";
  681.     }
  682.   else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
  683.     {
  684.       obstack = function_maybepermanent_obstack;
  685.       obstack_name = "function maybepermanent obstack";
  686.     }
  687.   else if (_obstack_allocated_p (&temp_decl_obstack, object))
  688.     {
  689.       obstack = &temp_decl_obstack;
  690.       obstack_name = "temp_decl_obstack";
  691.     }
  692.  
  693.   /* Check to see if the object is in the free area of the obstack. */
  694.   if (obstack != NULL)
  695.     {
  696.       if (object >= obstack->next_free
  697.       && object < obstack->chunk_limit)
  698.     fprintf (file, "%s in free portion of obstack %s",
  699.          prefix, obstack_name);
  700.       else
  701.     fprintf (file, "%s allocated from %s", prefix, obstack_name);
  702.     }
  703.   else
  704.     fprintf (file, "%s not allocated from any obstack", prefix);
  705. }
  706.  
  707. void
  708. debug_obstack (object)
  709.      char *object;
  710. {
  711.   print_obstack_name (object, stderr, "object");
  712.   fprintf (stderr, ".\n");
  713. }
  714.  
  715. /* Return 1 if OBJ is in the permanent obstack.
  716.    This is slow, and should be used only for debugging.
  717.    Use TREE_PERMANENT for other purposes.  */
  718.  
  719. int
  720. object_permanent_p (obj)
  721.      tree obj;
  722. {
  723.   return _obstack_allocated_p (&permanent_obstack, obj);
  724. }
  725.  
  726. /* Start a level of momentary allocation.
  727.    In C, each compound statement has its own level
  728.    and that level is freed at the end of each statement.
  729.    All expression nodes are allocated in the momentary allocation level.  */
  730.  
  731. void
  732. push_momentary ()
  733. {
  734.   struct momentary_level *tem
  735.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  736.                         sizeof (struct momentary_level));
  737.   tem->prev = momentary_stack;
  738.   tem->base = (char *) obstack_base (&momentary_obstack);
  739.   tem->obstack = expression_obstack;
  740.   momentary_stack = tem;
  741.   expression_obstack = &momentary_obstack;
  742. }
  743.  
  744. /* Free all the storage in the current momentary-allocation level.
  745.    In C, this happens at the end of each statement.  */
  746.  
  747. void
  748. clear_momentary ()
  749. {
  750.   obstack_free (&momentary_obstack, momentary_stack->base);
  751. }
  752.  
  753. /* Discard a level of momentary allocation.
  754.    In C, this happens at the end of each compound statement.
  755.    Restore the status of expression node allocation
  756.    that was in effect before this level was created.  */
  757.  
  758. void
  759. pop_momentary ()
  760. {
  761.   struct momentary_level *tem = momentary_stack;
  762.   momentary_stack = tem->prev;
  763.   expression_obstack = tem->obstack;
  764.   /* We can't free TEM from the momentary_obstack, because there might
  765.      be objects above it which have been saved.  We can free back to the
  766.      stack of the level we are popping off though.  */
  767.   obstack_free (&momentary_obstack, tem->base);
  768. }
  769.  
  770. /* Pop back to the previous level of momentary allocation,
  771.    but don't free any momentary data just yet.  */
  772.  
  773. void
  774. pop_momentary_nofree ()
  775. {
  776.   struct momentary_level *tem = momentary_stack;
  777.   momentary_stack = tem->prev;
  778.   expression_obstack = tem->obstack;
  779. }
  780.  
  781. /* Call when starting to parse a declaration:
  782.    make expressions in the declaration last the length of the function.
  783.    Returns an argument that should be passed to resume_momentary later.  */
  784.  
  785. int
  786. suspend_momentary ()
  787. {
  788.   register int tem = expression_obstack == &momentary_obstack;
  789.   expression_obstack = saveable_obstack;
  790.   return tem;
  791. }
  792.  
  793. /* Call when finished parsing a declaration:
  794.    restore the treatment of node-allocation that was
  795.    in effect before the suspension.
  796.    YES should be the value previously returned by suspend_momentary.  */
  797.  
  798. void
  799. resume_momentary (yes)
  800.      int yes;
  801. {
  802.   if (yes)
  803.     expression_obstack = &momentary_obstack;
  804. }
  805.  
  806. /* Init the tables indexed by tree code.
  807.    Note that languages can add to these tables to define their own codes.  */
  808.  
  809. void
  810. init_tree_codes ()
  811. {
  812.   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
  813.   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
  814.   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
  815.   bcopy ((char *) standard_tree_code_type, (char *) tree_code_type,
  816.      sizeof (standard_tree_code_type));
  817.   bcopy ((char *) standard_tree_code_length, (char *) tree_code_length,
  818.      sizeof (standard_tree_code_length));
  819.   bcopy ((char *) standard_tree_code_name, (char *) tree_code_name,
  820.      sizeof (standard_tree_code_name));
  821. }
  822.  
  823. /* Return a newly allocated node of code CODE.
  824.    Initialize the node's unique id and its TREE_PERMANENT flag.
  825.    For decl and type nodes, some other fields are initialized.
  826.    The rest of the node is initialized to zero.
  827.  
  828.    Achoo!  I got a code in the node.  */
  829.  
  830. tree
  831. make_node (code)
  832.      enum tree_code code;
  833. {
  834.   register tree t;
  835.   register int type = TREE_CODE_CLASS (code);
  836.   register int length;
  837.   register struct obstack *obstack = current_obstack;
  838.   register int i;
  839.   register tree_node_kind kind;
  840.  
  841.   switch (type)
  842.     {
  843.     case 'd':  /* A decl node */
  844. #ifdef GATHER_STATISTICS
  845.       kind = d_kind;
  846. #endif
  847.       length = sizeof (struct tree_decl);
  848.       /* All decls in an inline function need to be saved.  */
  849.       if (obstack != &permanent_obstack)
  850.     obstack = saveable_obstack;
  851.  
  852.       /* PARM_DECLs go on the context of the parent. If this is a nested
  853.      function, then we must allocate the PARM_DECL on the parent's
  854.      obstack, so that they will live to the end of the parent's
  855.      closing brace.  This is neccesary in case we try to inline the
  856.      function into its parent.
  857.  
  858.      PARM_DECLs of top-level functions do not have this problem.  However,
  859.      we allocate them where we put the FUNCTION_DECL for languauges such as
  860.      Ada that need to consult some flags in the PARM_DECLs of the function
  861.      when calling it. 
  862.  
  863.      See comment in restore_tree_status for why we can't put this
  864.      in function_obstack.  */
  865.       if (code == PARM_DECL && obstack != &permanent_obstack)
  866.     {
  867.       tree context = 0;
  868.       if (current_function_decl)
  869.         context = decl_function_context (current_function_decl);
  870.  
  871.       if (context)
  872.         obstack
  873.           = find_function_data (context)->function_maybepermanent_obstack;
  874.     }
  875.       break;
  876.  
  877.     case 't':  /* a type node */
  878. #ifdef GATHER_STATISTICS
  879.       kind = t_kind;
  880. #endif
  881.       length = sizeof (struct tree_type);
  882.       /* All data types are put where we can preserve them if nec.  */
  883.       if (obstack != &permanent_obstack)
  884.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  885.       break;
  886.  
  887.     case 'b':  /* a lexical block */
  888. #ifdef GATHER_STATISTICS
  889.       kind = b_kind;
  890. #endif
  891.       length = sizeof (struct tree_block);
  892.       /* All BLOCK nodes are put where we can preserve them if nec.  */
  893.       if (obstack != &permanent_obstack)
  894.     obstack = saveable_obstack;
  895.       break;
  896.  
  897.     case 's':  /* an expression with side effects */
  898. #ifdef GATHER_STATISTICS
  899.       kind = s_kind;
  900.       goto usual_kind;
  901. #endif
  902.     case 'r':  /* a reference */
  903. #ifdef GATHER_STATISTICS
  904.       kind = r_kind;
  905.       goto usual_kind;
  906. #endif
  907.     case 'e':  /* an expression */
  908.     case '<':  /* a comparison expression */
  909.     case '1':  /* a unary arithmetic expression */
  910.     case '2':  /* a binary arithmetic expression */
  911. #ifdef GATHER_STATISTICS
  912.       kind = e_kind;
  913.     usual_kind:
  914. #endif
  915.       obstack = expression_obstack;
  916.       /* All BIND_EXPR nodes are put where we can preserve them if nec.  */
  917.       if (code == BIND_EXPR && obstack != &permanent_obstack)
  918.     obstack = saveable_obstack;
  919.       length = sizeof (struct tree_exp)
  920.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  921.       break;
  922.  
  923.     case 'c':  /* a constant */
  924. #ifdef GATHER_STATISTICS
  925.       kind = c_kind;
  926. #endif
  927.       obstack = expression_obstack;
  928.  
  929.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  930.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  931.      which might be wider than a pointer (e.g., long long).  Similarly
  932.      for REAL_CST, since the number of words is machine-dependent due
  933.      to varying size and alignment of `double'.  */
  934.  
  935.       if (code == INTEGER_CST)
  936.     length = sizeof (struct tree_int_cst);
  937.       else if (code == REAL_CST)
  938.     length = sizeof (struct tree_real_cst);
  939.       else
  940.     length = sizeof (struct tree_common)
  941.       + tree_code_length[(int) code] * sizeof (char *);
  942.       break;
  943.  
  944.     case 'x':  /* something random, like an identifier.  */
  945. #ifdef GATHER_STATISTICS
  946.       if (code == IDENTIFIER_NODE)
  947.     kind = id_kind;
  948.       else if (code == OP_IDENTIFIER)
  949.     kind = op_id_kind;
  950.       else if (code == TREE_VEC)
  951.     kind = vec_kind;
  952.       else
  953.     kind = x_kind;
  954. #endif
  955.       length = sizeof (struct tree_common)
  956.     + tree_code_length[(int) code] * sizeof (char *);
  957.       /* Identifier nodes are always permanent since they are
  958.      unique in a compiler run.  */
  959.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  960.       break;
  961.  
  962.     default:
  963.       abort ();
  964.     }
  965.  
  966.   t = (tree) obstack_alloc (obstack, length);
  967.  
  968. #ifdef GATHER_STATISTICS
  969.   tree_node_counts[(int)kind]++;
  970.   tree_node_sizes[(int)kind] += length;
  971. #endif
  972.  
  973.   /* Clear a word at a time.  */
  974.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  975.     ((int *) t)[i] = 0;
  976.   /* Clear any extra bytes.  */
  977.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  978.     ((char *) t)[i] = 0;
  979.  
  980.   TREE_SET_CODE (t, code);
  981.   if (obstack == &permanent_obstack)
  982.     TREE_PERMANENT (t) = 1;
  983.  
  984.   switch (type)
  985.     {
  986.     case 's':
  987.       TREE_SIDE_EFFECTS (t) = 1;
  988.       TREE_TYPE (t) = void_type_node;
  989.       break;
  990.  
  991.     case 'd':
  992.       if (code != FUNCTION_DECL)
  993.     DECL_ALIGN (t) = 1;
  994.       DECL_IN_SYSTEM_HEADER (t)
  995.     = in_system_header && (obstack == &permanent_obstack);
  996.       DECL_SOURCE_LINE (t) = lineno;
  997.       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
  998.       DECL_UID (t) = next_decl_uid++;
  999.       break;
  1000.  
  1001.     case 't':
  1002.       TYPE_UID (t) = next_type_uid++;
  1003.       TYPE_ALIGN (t) = 1;
  1004.       TYPE_MAIN_VARIANT (t) = t;
  1005.       TYPE_OBSTACK (t) = obstack;
  1006.       TYPE_ATTRIBUTES (t) = NULL_TREE;
  1007. #ifdef SET_DEFAULT_TYPE_ATTRIBUTES
  1008.       SET_DEFAULT_TYPE_ATTRIBUTES (t);
  1009. #endif
  1010.       break;
  1011.  
  1012.     case 'c':
  1013.       TREE_CONSTANT (t) = 1;
  1014.       break;
  1015.     }
  1016.  
  1017.   return t;
  1018. }
  1019.  
  1020. /* Return a new node with the same contents as NODE
  1021.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  1022.  
  1023. tree
  1024. copy_node (node)
  1025.      tree node;
  1026. {
  1027.   register tree t;
  1028.   register enum tree_code code = TREE_CODE (node);
  1029.   register int length;
  1030.   register int i;
  1031.  
  1032.   switch (TREE_CODE_CLASS (code))
  1033.     {
  1034.     case 'd':  /* A decl node */
  1035.       length = sizeof (struct tree_decl);
  1036.       break;
  1037.  
  1038.     case 't':  /* a type node */
  1039.       length = sizeof (struct tree_type);
  1040.       break;
  1041.  
  1042.     case 'b':  /* a lexical block node */
  1043.       length = sizeof (struct tree_block);
  1044.       break;
  1045.  
  1046.     case 'r':  /* a reference */
  1047.     case 'e':  /* an expression */
  1048.     case 's':  /* an expression with side effects */
  1049.     case '<':  /* a comparison expression */
  1050.     case '1':  /* a unary arithmetic expression */
  1051.     case '2':  /* a binary arithmetic expression */
  1052.       length = sizeof (struct tree_exp)
  1053.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  1054.       break;
  1055.  
  1056.     case 'c':  /* a constant */
  1057.       /* We can't use tree_code_length for INTEGER_CST, since the number of
  1058.      words is machine-dependent due to varying length of HOST_WIDE_INT,
  1059.      which might be wider than a pointer (e.g., long long).  Similarly
  1060.      for REAL_CST, since the number of words is machine-dependent due
  1061.      to varying size and alignment of `double'.  */
  1062.       if (code == INTEGER_CST)
  1063.         {
  1064.           length = sizeof (struct tree_int_cst);
  1065.           break;
  1066.         }
  1067.       else if (code == REAL_CST)
  1068.     {
  1069.       length = sizeof (struct tree_real_cst);
  1070.       break;
  1071.     }
  1072.  
  1073.     case 'x':  /* something random, like an identifier.  */
  1074.       length = sizeof (struct tree_common)
  1075.     + tree_code_length[(int) code] * sizeof (char *);
  1076.       if (code == TREE_VEC)
  1077.     length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
  1078.     }
  1079.  
  1080.   t = (tree) obstack_alloc (current_obstack, length);
  1081.  
  1082.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1083.     ((int *) t)[i] = ((int *) node)[i];
  1084.   /* Clear any extra bytes.  */
  1085.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  1086.     ((char *) t)[i] = ((char *) node)[i];
  1087.  
  1088.   TREE_CHAIN (t) = 0;
  1089.  
  1090.   if (TREE_CODE_CLASS (code) == 'd')
  1091.     DECL_UID (t) = next_decl_uid++;
  1092.   else if (TREE_CODE_CLASS (code) == 't')
  1093.     {
  1094.       TYPE_UID (t) = next_type_uid++;
  1095.       TYPE_OBSTACK (t) = current_obstack;
  1096.     }
  1097.  
  1098.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  1099.  
  1100.   return t;
  1101. }
  1102.  
  1103. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  1104.    For example, this can copy a list made of TREE_LIST nodes.  */
  1105.  
  1106. tree
  1107. copy_list (list)
  1108.      tree list;
  1109. {
  1110.   tree head;
  1111.   register tree prev, next;
  1112.  
  1113.   if (list == 0)
  1114.     return 0;
  1115.  
  1116.   head = prev = copy_node (list);
  1117.   next = TREE_CHAIN (list);
  1118.   while (next)
  1119.     {
  1120.       TREE_CHAIN (prev) = copy_node (next);
  1121.       prev = TREE_CHAIN (prev);
  1122.       next = TREE_CHAIN (next);
  1123.     }
  1124.   return head;
  1125. }
  1126.  
  1127. #define HASHBITS 30
  1128.  
  1129. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  1130.    If an identifier with that name has previously been referred to,
  1131.    the same node is returned this time.  */
  1132.  
  1133. tree
  1134. get_identifier (text)
  1135.      register char *text;
  1136. {
  1137.   register int hi;
  1138.   register int i;
  1139.   register tree idp;
  1140.   register int len, hash_len;
  1141.  
  1142.   /* Compute length of text in len.  */
  1143.   for (len = 0; text[len]; len++);
  1144.  
  1145.   /* Decide how much of that length to hash on */
  1146.   hash_len = len;
  1147.   if (warn_id_clash && len > id_clash_len)
  1148.     hash_len = id_clash_len;
  1149.  
  1150.   /* Compute hash code */
  1151.   hi = hash_len * 613 + (unsigned)text[0];
  1152.   for (i = 1; i < hash_len; i += 2)
  1153.     hi = ((hi * 613) + (unsigned)(text[i]));
  1154.  
  1155.   hi &= (1 << HASHBITS) - 1;
  1156.   hi %= MAX_HASH_TABLE;
  1157.   
  1158.   /* Search table for identifier */
  1159.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1160.     if (IDENTIFIER_LENGTH (idp) == len
  1161.     && IDENTIFIER_POINTER (idp)[0] == text[0]
  1162.     && !bcmp (IDENTIFIER_POINTER (idp), text, len))
  1163.       return idp;        /* <-- return if found */
  1164.  
  1165.   /* Not found; optionally warn about a similar identifier */
  1166.   if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
  1167.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1168.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  1169.     {
  1170.       warning ("`%s' and `%s' identical in first %d characters",
  1171.            IDENTIFIER_POINTER (idp), text, id_clash_len);
  1172.       break;
  1173.     }
  1174.  
  1175.   if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
  1176.     abort ();            /* set_identifier_size hasn't been called.  */
  1177.  
  1178.   /* Not found, create one, add to chain */
  1179.   idp = make_node (IDENTIFIER_NODE);
  1180.   IDENTIFIER_LENGTH (idp) = len;
  1181. #ifdef GATHER_STATISTICS
  1182.   id_string_size += len;
  1183. #endif
  1184.  
  1185.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  1186.  
  1187.   TREE_CHAIN (idp) = hash_table[hi];
  1188.   hash_table[hi] = idp;
  1189.   return idp;            /* <-- return if created */
  1190. }
  1191.  
  1192. /* Enable warnings on similar identifiers (if requested).
  1193.    Done after the built-in identifiers are created.  */
  1194.  
  1195. void
  1196. start_identifier_warnings ()
  1197. {
  1198.   do_identifier_warnings = 1;
  1199. }
  1200.  
  1201. /* Record the size of an identifier node for the language in use.
  1202.    SIZE is the total size in bytes.
  1203.    This is called by the language-specific files.  This must be
  1204.    called before allocating any identifiers.  */
  1205.  
  1206. void
  1207. set_identifier_size (size)
  1208.      int size;
  1209. {
  1210.   tree_code_length[(int) IDENTIFIER_NODE]
  1211.     = (size - sizeof (struct tree_common)) / sizeof (tree);
  1212. }
  1213.  
  1214. /* Return a newly constructed INTEGER_CST node whose constant value
  1215.    is specified by the two ints LOW and HI.
  1216.    The TREE_TYPE is set to `int'. 
  1217.  
  1218.    This function should be used via the `build_int_2' macro.  */
  1219.  
  1220. tree
  1221. build_int_2_wide (low, hi)
  1222.      HOST_WIDE_INT low, hi;
  1223. {
  1224.   register tree t = make_node (INTEGER_CST);
  1225.   TREE_INT_CST_LOW (t) = low;
  1226.   TREE_INT_CST_HIGH (t) = hi;
  1227.   TREE_TYPE (t) = integer_type_node;
  1228.   return t;
  1229. }
  1230.  
  1231. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  1232.  
  1233. tree
  1234. build_real (type, d)
  1235.      tree type;
  1236.      REAL_VALUE_TYPE d;
  1237. {
  1238.   tree v;
  1239.   int overflow = 0;
  1240.  
  1241.   /* Check for valid float value for this type on this target machine;
  1242.      if not, can print error message and store a valid value in D.  */
  1243. #ifdef CHECK_FLOAT_VALUE
  1244.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1245. #endif
  1246.  
  1247.   v = make_node (REAL_CST);
  1248.   TREE_TYPE (v) = type;
  1249.   TREE_REAL_CST (v) = d;
  1250.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1251.   return v;
  1252. }
  1253.  
  1254. /* Return a new REAL_CST node whose type is TYPE
  1255.    and whose value is the integer value of the INTEGER_CST node I.  */
  1256.  
  1257. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1258.  
  1259. REAL_VALUE_TYPE
  1260. real_value_from_int_cst (i)
  1261.      tree i;
  1262. {
  1263.   REAL_VALUE_TYPE d;
  1264.   REAL_VALUE_TYPE e;
  1265.   /* Some 386 compilers mishandle unsigned int to float conversions,
  1266.      so introduce a temporary variable E to avoid those bugs.  */
  1267.  
  1268. #ifdef REAL_ARITHMETIC
  1269.   if (! TREE_UNSIGNED (TREE_TYPE (i)))
  1270.     REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1271.   else
  1272.     REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1273. #else /* not REAL_ARITHMETIC */
  1274.   if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
  1275.     {
  1276.       d = (double) (~ TREE_INT_CST_HIGH (i));
  1277.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1278.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1279.       d *= e;
  1280.       e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
  1281.       d += e;
  1282.       d = (- d - 1.0);
  1283.     }
  1284.   else
  1285.     {
  1286.       d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
  1287.       e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1288.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1289.       d *= e;
  1290.       e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
  1291.       d += e;
  1292.     }
  1293. #endif /* not REAL_ARITHMETIC */
  1294.   return d;
  1295. }
  1296.  
  1297. /* This function can't be implemented if we can't do arithmetic
  1298.    on the float representation.  */
  1299.  
  1300. tree
  1301. build_real_from_int_cst (type, i)
  1302.      tree type;
  1303.      tree i;
  1304. {
  1305.   tree v;
  1306.   int overflow = TREE_OVERFLOW (i);
  1307.   REAL_VALUE_TYPE d;
  1308.   jmp_buf float_error;
  1309.  
  1310.   v = make_node (REAL_CST);
  1311.   TREE_TYPE (v) = type;
  1312.  
  1313.   if (setjmp (float_error))
  1314.     {
  1315.       d = dconst0;
  1316.       overflow = 1;
  1317.       goto got_it;
  1318.     }
  1319.  
  1320.   set_float_handler (float_error);
  1321.  
  1322.   d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
  1323.  
  1324.   /* Check for valid float value for this type on this target machine.  */
  1325.  
  1326.  got_it:
  1327.   set_float_handler (NULL_PTR);
  1328.  
  1329. #ifdef CHECK_FLOAT_VALUE
  1330.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d, overflow);
  1331. #endif
  1332.  
  1333.   TREE_REAL_CST (v) = d;
  1334.   TREE_OVERFLOW (v) = TREE_CONSTANT_OVERFLOW (v) = overflow;
  1335.   return v;
  1336. }
  1337.  
  1338. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1339.  
  1340. /* Return a newly constructed STRING_CST node whose value is
  1341.    the LEN characters at STR.
  1342.    The TREE_TYPE is not initialized.  */
  1343.  
  1344. tree
  1345. build_string (len, str)
  1346.      int len;
  1347.      char *str;
  1348. {
  1349.   /* Put the string in saveable_obstack since it will be placed in the RTL
  1350.      for an "asm" statement and will also be kept around a while if
  1351.      deferring constant output in varasm.c.  */
  1352.  
  1353.   register tree s = make_node (STRING_CST);
  1354.   TREE_STRING_LENGTH (s) = len;
  1355.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  1356.   return s;
  1357. }
  1358.  
  1359. /* Return a newly constructed COMPLEX_CST node whose value is
  1360.    specified by the real and imaginary parts REAL and IMAG.
  1361.    Both REAL and IMAG should be constant nodes.
  1362.    The TREE_TYPE is not initialized.  */
  1363.  
  1364. tree
  1365. build_complex (real, imag)
  1366.      tree real, imag;
  1367. {
  1368.   register tree t = make_node (COMPLEX_CST);
  1369.  
  1370.   TREE_REALPART (t) = real;
  1371.   TREE_IMAGPART (t) = imag;
  1372.   TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
  1373.   TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
  1374.   TREE_CONSTANT_OVERFLOW (t)
  1375.     = TREE_CONSTANT_OVERFLOW (real) | TREE_CONSTANT_OVERFLOW (imag);
  1376.   return t;
  1377. }
  1378.  
  1379. /* Build a newly constructed TREE_VEC node of length LEN.  */
  1380. tree
  1381. make_tree_vec (len)
  1382.      int len;
  1383. {
  1384.   register tree t;
  1385.   register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
  1386.   register struct obstack *obstack = current_obstack;
  1387.   register int i;
  1388.  
  1389. #ifdef GATHER_STATISTICS
  1390.   tree_node_counts[(int)vec_kind]++;
  1391.   tree_node_sizes[(int)vec_kind] += length;
  1392. #endif
  1393.  
  1394.   t = (tree) obstack_alloc (obstack, length);
  1395.  
  1396.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1397.     ((int *) t)[i] = 0;
  1398.  
  1399.   TREE_SET_CODE (t, TREE_VEC);
  1400.   TREE_VEC_LENGTH (t) = len;
  1401.   if (obstack == &permanent_obstack)
  1402.     TREE_PERMANENT (t) = 1;
  1403.  
  1404.   return t;
  1405. }
  1406.  
  1407. /* Return 1 if EXPR is the integer constant zero.  */
  1408.  
  1409. int
  1410. integer_zerop (expr)
  1411.      tree expr;
  1412. {
  1413.   STRIP_NOPS (expr);
  1414.  
  1415.   return (TREE_CODE (expr) == INTEGER_CST
  1416.       && TREE_INT_CST_LOW (expr) == 0
  1417.       && TREE_INT_CST_HIGH (expr) == 0);
  1418. }
  1419.  
  1420. /* Return 1 if EXPR is the integer constant one.  */
  1421.  
  1422. int
  1423. integer_onep (expr)
  1424.      tree expr;
  1425. {
  1426.   STRIP_NOPS (expr);
  1427.  
  1428.   return (TREE_CODE (expr) == INTEGER_CST
  1429.       && TREE_INT_CST_LOW (expr) == 1
  1430.       && TREE_INT_CST_HIGH (expr) == 0);
  1431. }
  1432.  
  1433. /* Return 1 if EXPR is an integer containing all 1's
  1434.    in as much precision as it contains.  */
  1435.  
  1436. int
  1437. integer_all_onesp (expr)
  1438.      tree expr;
  1439. {
  1440.   register int prec;
  1441.   register int uns;
  1442.  
  1443.   STRIP_NOPS (expr);
  1444.  
  1445.   if (TREE_CODE (expr) != INTEGER_CST)
  1446.     return 0;
  1447.  
  1448.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  1449.   if (!uns)
  1450.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  1451.  
  1452.   prec = TYPE_PRECISION (TREE_TYPE (expr));
  1453.   if (prec >= HOST_BITS_PER_WIDE_INT)
  1454.     {
  1455.       int high_value, shift_amount;
  1456.  
  1457.       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
  1458.  
  1459.       if (shift_amount > HOST_BITS_PER_WIDE_INT)
  1460.     /* Can not handle precisions greater than twice the host int size.  */
  1461.     abort ();
  1462.       else if (shift_amount == HOST_BITS_PER_WIDE_INT)
  1463.     /* Shifting by the host word size is undefined according to the ANSI
  1464.        standard, so we must handle this as a special case.  */
  1465.     high_value = -1;
  1466.       else
  1467.     high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
  1468.  
  1469.       return TREE_INT_CST_LOW (expr) == -1
  1470.     && TREE_INT_CST_HIGH (expr) == high_value;
  1471.     }
  1472.   else
  1473.     return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
  1474. }
  1475.  
  1476. /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
  1477.    one bit on).  */
  1478.  
  1479. int
  1480. integer_pow2p (expr)
  1481.      tree expr;
  1482. {
  1483.   HOST_WIDE_INT high, low;
  1484.  
  1485.   STRIP_NOPS (expr);
  1486.  
  1487.   if (TREE_CODE (expr) != INTEGER_CST)
  1488.     return 0;
  1489.  
  1490.   high = TREE_INT_CST_HIGH (expr);
  1491.   low = TREE_INT_CST_LOW (expr);
  1492.  
  1493.   if (high == 0 && low == 0)
  1494.     return 0;
  1495.  
  1496.   return ((high == 0 && (low & (low - 1)) == 0)
  1497.       || (low == 0 && (high & (high - 1)) == 0));
  1498. }
  1499.  
  1500. /* Return 1 if EXPR is the real constant zero.  */
  1501.  
  1502. int
  1503. real_zerop (expr)
  1504.      tree expr;
  1505. {
  1506.   STRIP_NOPS (expr);
  1507.  
  1508.   return (TREE_CODE (expr) == REAL_CST
  1509.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
  1510. }
  1511.  
  1512. /* Return 1 if EXPR is the real constant one.  */
  1513.  
  1514. int
  1515. real_onep (expr)
  1516.      tree expr;
  1517. {
  1518.   STRIP_NOPS (expr);
  1519.  
  1520.   return (TREE_CODE (expr) == REAL_CST
  1521.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
  1522. }
  1523.  
  1524. /* Return 1 if EXPR is the real constant two.  */
  1525.  
  1526. int
  1527. real_twop (expr)
  1528.      tree expr;
  1529. {
  1530.   STRIP_NOPS (expr);
  1531.  
  1532.   return (TREE_CODE (expr) == REAL_CST
  1533.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
  1534. }
  1535.  
  1536. /* Nonzero if EXP is a constant or a cast of a constant.  */
  1537.  
  1538. int
  1539. really_constant_p (exp)
  1540.      tree exp;
  1541. {
  1542.   /* This is not quite the same as STRIP_NOPS.  It does more.  */
  1543.   while (TREE_CODE (exp) == NOP_EXPR
  1544.      || TREE_CODE (exp) == CONVERT_EXPR
  1545.      || TREE_CODE (exp) == NON_LVALUE_EXPR)
  1546.     exp = TREE_OPERAND (exp, 0);
  1547.   return TREE_CONSTANT (exp);
  1548. }
  1549.  
  1550. /* Return first list element whose TREE_VALUE is ELEM.
  1551.    Return 0 if ELEM is not it LIST.  */
  1552.  
  1553. tree
  1554. value_member (elem, list)
  1555.      tree elem, list;
  1556. {
  1557.   while (list)
  1558.     {
  1559.       if (elem == TREE_VALUE (list))
  1560.     return list;
  1561.       list = TREE_CHAIN (list);
  1562.     }
  1563.   return NULL_TREE;
  1564. }
  1565.  
  1566. /* Return first list element whose TREE_PURPOSE is ELEM.
  1567.    Return 0 if ELEM is not it LIST.  */
  1568.  
  1569. tree
  1570. purpose_member (elem, list)
  1571.      tree elem, list;
  1572. {
  1573.   while (list)
  1574.     {
  1575.       if (elem == TREE_PURPOSE (list))
  1576.     return list;
  1577.       list = TREE_CHAIN (list);
  1578.     }
  1579.   return NULL_TREE;
  1580. }
  1581.  
  1582. /* Return first list element whose BINFO_TYPE is ELEM.
  1583.    Return 0 if ELEM is not it LIST.  */
  1584.  
  1585. tree
  1586. binfo_member (elem, list)
  1587.      tree elem, list;
  1588. {
  1589.   while (list)
  1590.     {
  1591.       if (elem == BINFO_TYPE (list))
  1592.     return list;
  1593.       list = TREE_CHAIN (list);
  1594.     }
  1595.   return NULL_TREE;
  1596. }
  1597.  
  1598. /* Return nonzero if ELEM is part of the chain CHAIN.  */
  1599.  
  1600. int
  1601. chain_member (elem, chain)
  1602.      tree elem, chain;
  1603. {
  1604.   while (chain)
  1605.     {
  1606.       if (elem == chain)
  1607.     return 1;
  1608.       chain = TREE_CHAIN (chain);
  1609.     }
  1610.  
  1611.   return 0;
  1612. }
  1613.  
  1614. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  1615.    We expect a null pointer to mark the end of the chain.
  1616.    This is the Lisp primitive `length'.  */
  1617.  
  1618. int
  1619. list_length (t)
  1620.      tree t;
  1621. {
  1622.   register tree tail;
  1623.   register int len = 0;
  1624.  
  1625.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  1626.     len++;
  1627.  
  1628.   return len;
  1629. }
  1630.  
  1631. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  1632.    by modifying the last node in chain 1 to point to chain 2.
  1633.    This is the Lisp primitive `nconc'.  */
  1634.  
  1635. tree
  1636. chainon (op1, op2)
  1637.      tree op1, op2;
  1638. {
  1639.  
  1640.   if (op1)
  1641.     {
  1642.       register tree t1;
  1643.       register tree t2;
  1644.  
  1645.       for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
  1646.     ;
  1647.       TREE_CHAIN (t1) = op2;
  1648.       for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
  1649.         if (t2 == t1)
  1650.           abort ();  /* Circularity created.  */
  1651.       return op1;
  1652.     }
  1653.   else return op2;
  1654. }
  1655.  
  1656. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  1657.  
  1658. tree
  1659. tree_last (chain)
  1660.      register tree chain;
  1661. {
  1662.   register tree next;
  1663.   if (chain)
  1664.     while (next = TREE_CHAIN (chain))
  1665.       chain = next;
  1666.   return chain;
  1667. }
  1668.  
  1669. /* Reverse the order of elements in the chain T,
  1670.    and return the new head of the chain (old last element).  */
  1671.  
  1672. tree
  1673. nreverse (t)
  1674.      tree t;
  1675. {
  1676.   register tree prev = 0, decl, next;
  1677.   for (decl = t; decl; decl = next)
  1678.     {
  1679.       next = TREE_CHAIN (decl);
  1680.       TREE_CHAIN (decl) = prev;
  1681.       prev = decl;
  1682.     }
  1683.   return prev;
  1684. }
  1685.  
  1686. /* Given a chain CHAIN of tree nodes,
  1687.    construct and return a list of those nodes.  */
  1688.  
  1689. tree
  1690. listify (chain)
  1691.      tree chain;
  1692. {
  1693.   tree result = NULL_TREE;
  1694.   tree in_tail = chain;
  1695.   tree out_tail = NULL_TREE;
  1696.  
  1697.   while (in_tail)
  1698.     {
  1699.       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
  1700.       if (out_tail)
  1701.     TREE_CHAIN (out_tail) = next;
  1702.       else
  1703.     result = next;
  1704.       out_tail = next;
  1705.       in_tail = TREE_CHAIN (in_tail);
  1706.     }
  1707.  
  1708.   return result;
  1709. }
  1710.  
  1711. /* Return a newly created TREE_LIST node whose
  1712.    purpose and value fields are PARM and VALUE.  */
  1713.  
  1714. tree
  1715. build_tree_list (parm, value)
  1716.      tree parm, value;
  1717. {
  1718.   register tree t = make_node (TREE_LIST);
  1719.   TREE_PURPOSE (t) = parm;
  1720.   TREE_VALUE (t) = value;
  1721.   return t;
  1722. }
  1723.  
  1724. /* Similar, but build on the temp_decl_obstack.  */
  1725.  
  1726. tree
  1727. build_decl_list (parm, value)
  1728.      tree parm, value;
  1729. {
  1730.   register tree node;
  1731.   register struct obstack *ambient_obstack = current_obstack;
  1732.   current_obstack = &temp_decl_obstack;
  1733.   node = build_tree_list (parm, value);
  1734.   current_obstack = ambient_obstack;
  1735.   return node;
  1736. }
  1737.  
  1738. /* Return a newly created TREE_LIST node whose
  1739.    purpose and value fields are PARM and VALUE
  1740.    and whose TREE_CHAIN is CHAIN.  */
  1741.  
  1742. tree
  1743. tree_cons (purpose, value, chain)
  1744.      tree purpose, value, chain;
  1745. {
  1746. #if 0
  1747.   register tree node = make_node (TREE_LIST);
  1748. #else
  1749.   register int i;
  1750.   register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
  1751. #ifdef GATHER_STATISTICS
  1752.   tree_node_counts[(int)x_kind]++;
  1753.   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
  1754. #endif
  1755.  
  1756.   for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
  1757.     ((int *) node)[i] = 0;
  1758.  
  1759.   TREE_SET_CODE (node, TREE_LIST);
  1760.   if (current_obstack == &permanent_obstack)
  1761.     TREE_PERMANENT (node) = 1;
  1762. #endif
  1763.  
  1764.   TREE_CHAIN (node) = chain;
  1765.   TREE_PURPOSE (node) = purpose;
  1766.   TREE_VALUE (node) = value;
  1767.   return node;
  1768. }
  1769.  
  1770. /* Similar, but build on the temp_decl_obstack.  */
  1771.  
  1772. tree
  1773. decl_tree_cons (purpose, value, chain)
  1774.      tree purpose, value, chain;
  1775. {
  1776.   register tree node;
  1777.   register struct obstack *ambient_obstack = current_obstack;
  1778.   current_obstack = &temp_decl_obstack;
  1779.   node = tree_cons (purpose, value, chain);
  1780.   current_obstack = ambient_obstack;
  1781.   return node;
  1782. }
  1783.  
  1784. /* Same as `tree_cons' but make a permanent object.  */
  1785.  
  1786. tree
  1787. perm_tree_cons (purpose, value, chain)
  1788.      tree purpose, value, chain;
  1789. {
  1790.   register tree node;
  1791.   register struct obstack *ambient_obstack = current_obstack;
  1792.   current_obstack = &permanent_obstack;
  1793.  
  1794.   node = tree_cons (purpose, value, chain);
  1795.   current_obstack = ambient_obstack;
  1796.   return node;
  1797. }
  1798.  
  1799. /* Same as `tree_cons', but make this node temporary, regardless.  */
  1800.  
  1801. tree
  1802. temp_tree_cons (purpose, value, chain)
  1803.      tree purpose, value, chain;
  1804. {
  1805.   register tree node;
  1806.   register struct obstack *ambient_obstack = current_obstack;
  1807.   current_obstack = &temporary_obstack;
  1808.  
  1809.   node = tree_cons (purpose, value, chain);
  1810.   current_obstack = ambient_obstack;
  1811.   return node;
  1812. }
  1813.  
  1814. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  1815.  
  1816. tree
  1817. saveable_tree_cons (purpose, value, chain)
  1818.      tree purpose, value, chain;
  1819. {
  1820.   register tree node;
  1821.   register struct obstack *ambient_obstack = current_obstack;
  1822.   current_obstack = saveable_obstack;
  1823.  
  1824.   node = tree_cons (purpose, value, chain);
  1825.   current_obstack = ambient_obstack;
  1826.   return node;
  1827. }
  1828.  
  1829. /* Return the size nominally occupied by an object of type TYPE
  1830.    when it resides in memory.  The value is measured in units of bytes,
  1831.    and its data type is that normally used for type sizes
  1832.    (which is the first type created by make_signed_type or
  1833.    make_unsigned_type).  */
  1834.  
  1835. tree
  1836. size_in_bytes (type)
  1837.      tree type;
  1838. {
  1839.   tree t;
  1840.  
  1841.   if (type == error_mark_node)
  1842.     return integer_zero_node;
  1843.   type = TYPE_MAIN_VARIANT (type);
  1844.   if (TYPE_SIZE (type) == 0)
  1845.     {
  1846.       incomplete_type_error (NULL_TREE, type);
  1847.       return integer_zero_node;
  1848.     }
  1849.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1850.           size_int (BITS_PER_UNIT));
  1851.   if (TREE_CODE (t) == INTEGER_CST)
  1852.     force_fit_type (t, 0);
  1853.   return t;
  1854. }
  1855.  
  1856. /* Return the size of TYPE (in bytes) as an integer,
  1857.    or return -1 if the size can vary.  */
  1858.  
  1859. int
  1860. int_size_in_bytes (type)
  1861.      tree type;
  1862. {
  1863.   unsigned int size;
  1864.   if (type == error_mark_node)
  1865.     return 0;
  1866.   type = TYPE_MAIN_VARIANT (type);
  1867.   if (TYPE_SIZE (type) == 0)
  1868.     return -1;
  1869.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  1870.     return -1;
  1871.   if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
  1872.     {
  1873.       tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1874.                size_int (BITS_PER_UNIT));
  1875.       return TREE_INT_CST_LOW (t);
  1876.     }
  1877.   size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  1878.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  1879. }
  1880.  
  1881. /* Return, as a tree node, the number of elements for TYPE (which is an
  1882.    ARRAY_TYPE) minus one. This counts only elements of the top array.  */
  1883.  
  1884. tree
  1885. array_type_nelts (type)
  1886.      tree type;
  1887. {
  1888.   tree index_type = TYPE_DOMAIN (type);
  1889.  
  1890.   return (integer_zerop (TYPE_MIN_VALUE (index_type))
  1891.       ? TYPE_MAX_VALUE (index_type)
  1892.       : fold (build (MINUS_EXPR, TREE_TYPE (TYPE_MAX_VALUE (index_type)),
  1893.              TYPE_MAX_VALUE (index_type),
  1894.              TYPE_MIN_VALUE (index_type))));
  1895. }
  1896.  
  1897. /* Return nonzero if arg is static -- a reference to an object in
  1898.    static storage.  This is not the same as the C meaning of `static'.  */
  1899.  
  1900. int
  1901. staticp (arg)
  1902.      tree arg;
  1903. {
  1904.   switch (TREE_CODE (arg))
  1905.     {
  1906.     case FUNCTION_DECL:
  1907.       /* Nested functions aren't static.  Since taking their address
  1908.      involves a trampoline.  */
  1909.       if (decl_function_context (arg) != 0)
  1910.     return 0;
  1911.       /* ... fall through ... */
  1912.     case VAR_DECL:
  1913.       return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
  1914.  
  1915.     case CONSTRUCTOR:
  1916.       return TREE_STATIC (arg);
  1917.  
  1918.     case STRING_CST:
  1919.       return 1;
  1920.  
  1921.     case COMPONENT_REF:
  1922.     case BIT_FIELD_REF:
  1923.       return staticp (TREE_OPERAND (arg, 0));
  1924.  
  1925.     case INDIRECT_REF:
  1926.       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
  1927.  
  1928.     case ARRAY_REF:
  1929.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  1930.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  1931.     return staticp (TREE_OPERAND (arg, 0));
  1932.     }
  1933.  
  1934.   return 0;
  1935. }
  1936.  
  1937. /* Wrap a SAVE_EXPR around EXPR, if appropriate.
  1938.    Do this to any expression which may be used in more than one place,
  1939.    but must be evaluated only once.
  1940.  
  1941.    Normally, expand_expr would reevaluate the expression each time.
  1942.    Calling save_expr produces something that is evaluated and recorded
  1943.    the first time expand_expr is called on it.  Subsequent calls to
  1944.    expand_expr just reuse the recorded value.
  1945.  
  1946.    The call to expand_expr that generates code that actually computes
  1947.    the value is the first call *at compile time*.  Subsequent calls
  1948.    *at compile time* generate code to use the saved value.
  1949.    This produces correct result provided that *at run time* control
  1950.    always flows through the insns made by the first expand_expr
  1951.    before reaching the other places where the save_expr was evaluated.
  1952.    You, the caller of save_expr, must make sure this is so.
  1953.  
  1954.    Constants, and certain read-only nodes, are returned with no
  1955.    SAVE_EXPR because that is safe.  Expressions containing placeholders
  1956.    are not touched; see tree.def for an explanation of what these
  1957.    are used for.  */
  1958.  
  1959. tree
  1960. save_expr (expr)
  1961.      tree expr;
  1962. {
  1963.   register tree t = fold (expr);
  1964.  
  1965.   /* We don't care about whether this can be used as an lvalue in this
  1966.      context.  */
  1967.   while (TREE_CODE (t) == NON_LVALUE_EXPR)
  1968.     t = TREE_OPERAND (t, 0);
  1969.  
  1970.   /* If the tree evaluates to a constant, then we don't want to hide that
  1971.      fact (i.e. this allows further folding, and direct checks for constants).
  1972.      However, a read-only object that has side effects cannot be bypassed.
  1973.      Since it is no problem to reevaluate literals, we just return the 
  1974.      literal node. */
  1975.  
  1976.   if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
  1977.       || TREE_CODE (t) == SAVE_EXPR)
  1978.     return t;
  1979.  
  1980.   /* If T contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
  1981.      it means that the size or offset of some field of an object depends on
  1982.      the value within another field.
  1983.  
  1984.      Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
  1985.      and some variable since it would then need to be both evaluated once and
  1986.      evaluated more than once.  Front-ends must assure this case cannot
  1987.      happen by surrounding any such subexpressions in their own SAVE_EXPR
  1988.      and forcing evaluation at the proper time.  */
  1989.   if (contains_placeholder_p (t))
  1990.     return t;
  1991.  
  1992.   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
  1993.  
  1994.   /* This expression might be placed ahead of a jump to ensure that the
  1995.      value was computed on both sides of the jump.  So make sure it isn't
  1996.      eliminated as dead.  */
  1997.   TREE_SIDE_EFFECTS (t) = 1;
  1998.   return t;
  1999. }
  2000.  
  2001. /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
  2002.    or offset that depends on a field within a record.
  2003.  
  2004.    Note that we only allow such expressions within simple arithmetic
  2005.    or a COND_EXPR.  */
  2006.  
  2007. int
  2008. contains_placeholder_p (exp)
  2009.      tree exp;
  2010. {
  2011.   register enum tree_code code = TREE_CODE (exp);
  2012.   tree inner;
  2013.  
  2014.   /* If we have a WITH_RECORD_EXPR, it "cancels" any PLACEHOLDER_EXPR
  2015.      in it since it is supplying a value for it.  */
  2016.   if (code == WITH_RECORD_EXPR)
  2017.     return 0;
  2018.  
  2019.   switch (TREE_CODE_CLASS (code))
  2020.     {
  2021.     case 'r':
  2022.       for (inner = TREE_OPERAND (exp, 0);
  2023.        TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2024.        inner = TREE_OPERAND (inner, 0))
  2025.     ;
  2026.       return TREE_CODE (inner) == PLACEHOLDER_EXPR;
  2027.  
  2028.     case '1':
  2029.     case '2':  case '<':
  2030.     case 'e':
  2031.       switch (tree_code_length[(int) code])
  2032.     {
  2033.     case 1:
  2034.       return contains_placeholder_p (TREE_OPERAND (exp, 0));
  2035.     case 2:
  2036.       return (code != RTL_EXPR
  2037.           && code != CONSTRUCTOR
  2038.           && ! (code == SAVE_EXPR && SAVE_EXPR_RTL (exp) != 0)
  2039.           && code != WITH_RECORD_EXPR
  2040.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2041.               || contains_placeholder_p (TREE_OPERAND (exp, 1))));
  2042.     case 3:
  2043.       return (code == COND_EXPR
  2044.           && (contains_placeholder_p (TREE_OPERAND (exp, 0))
  2045.               || contains_placeholder_p (TREE_OPERAND (exp, 1))
  2046.               || contains_placeholder_p (TREE_OPERAND (exp, 2))));
  2047.     }
  2048.     }
  2049.  
  2050.   return 0;
  2051. }
  2052.  
  2053. /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
  2054.    return a tree with all occurrences of references to F in a
  2055.    PLACEHOLDER_EXPR replaced by R.   Note that we assume here that EXP
  2056.    contains only arithmetic expressions.  */
  2057.  
  2058. tree
  2059. substitute_in_expr (exp, f, r)
  2060.      tree exp;
  2061.      tree f;
  2062.      tree r;
  2063. {
  2064.   enum tree_code code = TREE_CODE (exp);
  2065.   tree inner;
  2066.  
  2067.   switch (TREE_CODE_CLASS (code))
  2068.     {
  2069.     case 'c':
  2070.     case 'd':
  2071.       return exp;
  2072.  
  2073.     case 'x':
  2074.       if (code == PLACEHOLDER_EXPR)
  2075.     return exp;
  2076.       break;
  2077.  
  2078.     case '1':
  2079.     case '2':
  2080.     case '<':
  2081.     case 'e':
  2082.       switch (tree_code_length[(int) code])
  2083.     {
  2084.     case 1:
  2085.       return fold (build1 (code, TREE_TYPE (exp),
  2086.                    substitute_in_expr (TREE_OPERAND (exp, 0),
  2087.                            f, r)));
  2088.  
  2089.     case 2:
  2090.       /* An RTL_EXPR cannot contain a PLACEHOLDER_EXPR; a CONSTRUCTOR
  2091.          could, but we don't support it.  */
  2092.       if (code == RTL_EXPR)
  2093.         return exp;
  2094.       else if (code == CONSTRUCTOR)
  2095.         abort ();
  2096.  
  2097.       return fold (build (code, TREE_TYPE (exp),
  2098.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2099.                   substitute_in_expr (TREE_OPERAND (exp, 1),
  2100.                           f, r)));
  2101.  
  2102.     case 3:
  2103.       /* It cannot be that anything inside a SAVE_EXPR contains a
  2104.          PLACEHOLDER_EXPR.  */
  2105.       if (code == SAVE_EXPR)
  2106.         return exp;
  2107.  
  2108.       if (code != COND_EXPR)
  2109.         abort ();
  2110.  
  2111.       return fold (build (code, TREE_TYPE (exp),
  2112.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2113.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2114.                   substitute_in_expr (TREE_OPERAND (exp, 2),
  2115.                           f, r)));
  2116.     }
  2117.  
  2118.       break;
  2119.  
  2120.     case 'r':
  2121.       switch (code)
  2122.     {
  2123.     case COMPONENT_REF:
  2124.       /* If this expression is getting a value from a PLACEHOLDER_EXPR
  2125.          and it is the right field, replace it with R.  */
  2126.       for (inner = TREE_OPERAND (exp, 0);
  2127.            TREE_CODE_CLASS (TREE_CODE (inner)) == 'r';
  2128.            inner = TREE_OPERAND (inner, 0))
  2129.         ;
  2130.       if (TREE_CODE (inner) == PLACEHOLDER_EXPR
  2131.           && TREE_OPERAND (exp, 1) == f)
  2132.         return r;
  2133.  
  2134.       return fold (build (code, TREE_TYPE (exp),
  2135.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2136.                   TREE_OPERAND (exp, 1)));
  2137.     case BIT_FIELD_REF:
  2138.       return fold (build (code, TREE_TYPE (exp),
  2139.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2140.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r),
  2141.                   substitute_in_expr (TREE_OPERAND (exp, 2), f, r)));
  2142.     case INDIRECT_REF:
  2143.     case BUFFER_REF:
  2144.       return fold (build1 (code, TREE_TYPE (exp),
  2145.                    substitute_in_expr (TREE_OPERAND (exp, 0),
  2146.                          f, r)));
  2147.     case OFFSET_REF:
  2148.       return fold (build (code, TREE_TYPE (exp),
  2149.                   substitute_in_expr (TREE_OPERAND (exp, 0), f, r),
  2150.                   substitute_in_expr (TREE_OPERAND (exp, 1), f, r)));
  2151.     }
  2152.     }
  2153.  
  2154.   /* If it wasn't one of the cases we handle, give up.  */
  2155.  
  2156.   abort ();
  2157. }
  2158.  
  2159. /* Given a type T, a FIELD_DECL F, and a replacement value R,
  2160.    return a new type with all size expressions that contain F
  2161.    updated by replacing F with R.  */
  2162.  
  2163. tree
  2164. substitute_in_type (t, f, r)
  2165.      tree t, f, r;
  2166. {
  2167.   switch (TREE_CODE (t))
  2168.     {
  2169.     case POINTER_TYPE:
  2170.     case VOID_TYPE:
  2171.       return t;
  2172.     case INTEGER_TYPE:
  2173.     case ENUMERAL_TYPE:
  2174.     case BOOLEAN_TYPE:
  2175.     case CHAR_TYPE:
  2176.       if ((TREE_CODE (TYPE_MIN_VALUE (t)) != INTEGER_CST
  2177.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2178.       || (TREE_CODE (TYPE_MAX_VALUE (t)) != INTEGER_CST
  2179.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2180.     return build_range_type (t,
  2181.                  substitute_in_expr (TYPE_MIN_VALUE (t), f, r),
  2182.                  substitute_in_expr (TYPE_MAX_VALUE (t), f, r));
  2183.       return t;
  2184.  
  2185.     case REAL_TYPE:
  2186.       if ((TYPE_MIN_VALUE (t) != 0
  2187.        && TREE_CODE (TYPE_MIN_VALUE (t)) != REAL_CST
  2188.        && contains_placeholder_p (TYPE_MIN_VALUE (t)))
  2189.       || (TYPE_MAX_VALUE (t) != 0
  2190.           && TREE_CODE (TYPE_MAX_VALUE (t)) != REAL_CST
  2191.           && contains_placeholder_p (TYPE_MAX_VALUE (t))))
  2192.     {
  2193.       t = build_type_copy (t);
  2194.  
  2195.       if (TYPE_MIN_VALUE (t))
  2196.         TYPE_MIN_VALUE (t) = substitute_in_expr (TYPE_MIN_VALUE (t), f, r);
  2197.       if (TYPE_MAX_VALUE (t))
  2198.         TYPE_MAX_VALUE (t) = substitute_in_expr (TYPE_MAX_VALUE (t), f, r);
  2199.     }
  2200.       return t;
  2201.  
  2202.     case COMPLEX_TYPE:
  2203.       return build_complex_type (substitute_in_type (TREE_TYPE (t), f, r));
  2204.  
  2205.     case OFFSET_TYPE:
  2206.     case METHOD_TYPE:
  2207.     case REFERENCE_TYPE:
  2208.     case FILE_TYPE:
  2209.     case SET_TYPE:
  2210.     case FUNCTION_TYPE:
  2211.     case LANG_TYPE:
  2212.       /* Don't know how to do these yet.  */
  2213.       abort ();
  2214.  
  2215.     case ARRAY_TYPE:
  2216.       t = build_array_type (substitute_in_type (TREE_TYPE (t), f, r),
  2217.                 substitute_in_type (TYPE_DOMAIN (t), f, r));
  2218.       TYPE_SIZE (t) = 0;
  2219.       layout_type (t);
  2220.       return t;
  2221.  
  2222.     case RECORD_TYPE:
  2223.     case UNION_TYPE:
  2224.     case QUAL_UNION_TYPE:
  2225.       {
  2226.     tree new = copy_node (t);
  2227.     tree field;
  2228.     tree last_field = 0;
  2229.  
  2230.     /* Start out with no fields, make new fields, and chain them
  2231.        in.  */
  2232.  
  2233.     TYPE_FIELDS (new) = 0;
  2234.     TYPE_SIZE (new) = 0;
  2235.  
  2236.     for (field = TYPE_FIELDS (t); field;
  2237.          field = TREE_CHAIN (field))
  2238.       {
  2239.         tree new_field = copy_node (field);
  2240.  
  2241.         TREE_TYPE (new_field)
  2242.           = substitute_in_type (TREE_TYPE (new_field), f, r);
  2243.  
  2244.         /* If this is an anonymous field and the type of this field is
  2245.            a UNION_TYPE or RECORD_TYPE with no elements, ignore it.  If
  2246.            the type just has one element, treat that as the field. 
  2247.            But don't do this if we are processing a QUAL_UNION_TYPE.  */
  2248.         if (TREE_CODE (t) != QUAL_UNION_TYPE && DECL_NAME (new_field) == 0
  2249.         && (TREE_CODE (TREE_TYPE (new_field)) == UNION_TYPE
  2250.             || TREE_CODE (TREE_TYPE (new_field)) == RECORD_TYPE))
  2251.           {
  2252.         if (TYPE_FIELDS (TREE_TYPE (new_field)) == 0)
  2253.           continue;
  2254.  
  2255.         if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field))) == 0)
  2256.           new_field = TYPE_FIELDS (TREE_TYPE (new_field));
  2257.           }
  2258.  
  2259.         DECL_CONTEXT (new_field) = new;
  2260.         DECL_SIZE (new_field) = 0;
  2261.  
  2262.         if (TREE_CODE (t) == QUAL_UNION_TYPE)
  2263.           {
  2264.         /* Do the substitution inside the qualifier and if we find
  2265.            that this field will not be present, omit it.  */
  2266.         DECL_QUALIFIER (new_field)
  2267.           = substitute_in_expr (DECL_QUALIFIER (field), f, r);
  2268.         if (integer_zerop (DECL_QUALIFIER (new_field)))
  2269.           continue;
  2270.           }
  2271.  
  2272.         if (last_field == 0)
  2273.           TYPE_FIELDS (new) = new_field;
  2274.         else
  2275.           TREE_CHAIN (last_field) = new_field;
  2276.  
  2277.         last_field = new_field;
  2278.  
  2279.         /* If this is a qualified type and this field will always be
  2280.            present, we are done.  */
  2281.         if (TREE_CODE (t) == QUAL_UNION_TYPE
  2282.         && integer_onep (DECL_QUALIFIER (new_field)))
  2283.           break;
  2284.       }
  2285.  
  2286.     /* If this used to be a qualified union type, but we now know what
  2287.        field will be present, make this a normal union.  */
  2288.     if (TREE_CODE (new) == QUAL_UNION_TYPE
  2289.         && (TYPE_FIELDS (new) == 0
  2290.         || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
  2291.       TREE_SET_CODE (new, UNION_TYPE);
  2292.  
  2293.     layout_type (new);
  2294.     return new;
  2295.       }
  2296.     }
  2297. }
  2298.  
  2299. /* Stabilize a reference so that we can use it any number of times
  2300.    without causing its operands to be evaluated more than once.
  2301.    Returns the stabilized reference.  This works by means of save_expr,
  2302.    so see the caveats in the comments about save_expr.
  2303.  
  2304.    Also allows conversion expressions whose operands are references.
  2305.    Any other kind of expression is returned unchanged.  */
  2306.  
  2307. tree
  2308. stabilize_reference (ref)
  2309.      tree ref;
  2310. {
  2311.   register tree result;
  2312.   register enum tree_code code = TREE_CODE (ref);
  2313.  
  2314.   switch (code)
  2315.     {
  2316.     case VAR_DECL:
  2317.     case PARM_DECL:
  2318.     case RESULT_DECL:
  2319.       /* No action is needed in this case.  */
  2320.       return ref;
  2321.  
  2322.     case NOP_EXPR:
  2323.     case CONVERT_EXPR:
  2324.     case FLOAT_EXPR:
  2325.     case FIX_TRUNC_EXPR:
  2326.     case FIX_FLOOR_EXPR:
  2327.     case FIX_ROUND_EXPR:
  2328.     case FIX_CEIL_EXPR:
  2329.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  2330.       break;
  2331.  
  2332.     case INDIRECT_REF:
  2333.       result = build_nt (INDIRECT_REF,
  2334.              stabilize_reference_1 (TREE_OPERAND (ref, 0)));
  2335.       break;
  2336.  
  2337.     case COMPONENT_REF:
  2338.       result = build_nt (COMPONENT_REF,
  2339.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2340.              TREE_OPERAND (ref, 1));
  2341.       break;
  2342.  
  2343.     case BIT_FIELD_REF:
  2344.       result = build_nt (BIT_FIELD_REF,
  2345.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2346.              stabilize_reference_1 (TREE_OPERAND (ref, 1)),
  2347.              stabilize_reference_1 (TREE_OPERAND (ref, 2)));
  2348.       break;
  2349.  
  2350.     case ARRAY_REF:
  2351.       result = build_nt (ARRAY_REF,
  2352.              stabilize_reference (TREE_OPERAND (ref, 0)),
  2353.              stabilize_reference_1 (TREE_OPERAND (ref, 1)));
  2354.       break;
  2355.  
  2356.       /* If arg isn't a kind of lvalue we recognize, make no change.
  2357.      Caller should recognize the error for an invalid lvalue.  */
  2358.     default:
  2359.       return ref;
  2360.  
  2361.     case ERROR_MARK:
  2362.       return error_mark_node;
  2363.     }
  2364.  
  2365.   TREE_TYPE (result) = TREE_TYPE (ref);
  2366.   TREE_READONLY (result) = TREE_READONLY (ref);
  2367.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
  2368.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  2369.   TREE_RAISES (result) = TREE_RAISES (ref);
  2370.  
  2371.   return result;
  2372. }
  2373.  
  2374. /* Subroutine of stabilize_reference; this is called for subtrees of
  2375.    references.  Any expression with side-effects must be put in a SAVE_EXPR
  2376.    to ensure that it is only evaluated once.
  2377.  
  2378.    We don't put SAVE_EXPR nodes around everything, because assigning very
  2379.    simple expressions to temporaries causes us to miss good opportunities
  2380.    for optimizations.  Among other things, the opportunity to fold in the
  2381.    addition of a constant into an addressing mode often gets lost, e.g.
  2382.    "y[i+1] += x;".  In general, we take the approach that we should not make
  2383.    an assignment unless we are forced into it - i.e., that any non-side effect
  2384.    operator should be allowed, and that cse should take care of coalescing
  2385.    multiple utterances of the same expression should that prove fruitful.  */
  2386.  
  2387. static tree
  2388. stabilize_reference_1 (e)
  2389.      tree e;
  2390. {
  2391.   register tree result;
  2392.   register enum tree_code code = TREE_CODE (e);
  2393.  
  2394.   /* We cannot ignore const expressions because it might be a reference
  2395.      to a const array but whose index contains side-effects.  But we can
  2396.      ignore things that are actual constant or that already have been
  2397.      handled by this function.  */
  2398.  
  2399.   if (TREE_CONSTANT (e) || code == SAVE_EXPR)
  2400.     return e;
  2401.  
  2402.   switch (TREE_CODE_CLASS (code))
  2403.     {
  2404.     case 'x':
  2405.     case 't':
  2406.     case 'd':
  2407.     case 'b':
  2408.     case '<':
  2409.     case 's':
  2410.     case 'e':
  2411.     case 'r':
  2412.       /* If the expression has side-effects, then encase it in a SAVE_EXPR
  2413.      so that it will only be evaluated once.  */
  2414.       /* The reference (r) and comparison (<) classes could be handled as
  2415.      below, but it is generally faster to only evaluate them once.  */
  2416.       if (TREE_SIDE_EFFECTS (e))
  2417.     return save_expr (e);
  2418.       return e;
  2419.  
  2420.     case 'c':
  2421.       /* Constants need no processing.  In fact, we should never reach
  2422.      here.  */
  2423.       return e;
  2424.       
  2425.     case '2':
  2426.       /* Division is slow and tends to be compiled with jumps,
  2427.      especially the division by powers of 2 that is often
  2428.      found inside of an array reference.  So do it just once.  */
  2429.       if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
  2430.       || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
  2431.       || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
  2432.       || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
  2433.     return save_expr (e);
  2434.       /* Recursively stabilize each operand.  */
  2435.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
  2436.              stabilize_reference_1 (TREE_OPERAND (e, 1)));
  2437.       break;
  2438.  
  2439.     case '1':
  2440.       /* Recursively stabilize each operand.  */
  2441.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
  2442.       break;
  2443.  
  2444.     default:
  2445.       abort ();
  2446.     }
  2447.   
  2448.   TREE_TYPE (result) = TREE_TYPE (e);
  2449.   TREE_READONLY (result) = TREE_READONLY (e);
  2450.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
  2451.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
  2452.   TREE_RAISES (result) = TREE_RAISES (e);
  2453.  
  2454.   return result;
  2455. }
  2456.  
  2457. /* Low-level constructors for expressions.  */
  2458.  
  2459. /* Build an expression of code CODE, data type TYPE,
  2460.    and operands as specified by the arguments ARG1 and following arguments.
  2461.    Expressions and reference nodes can be created this way.
  2462.    Constants, decls, types and misc nodes cannot be.  */
  2463.  
  2464. tree
  2465. build VPROTO((enum tree_code code, tree tt, ...))
  2466. {
  2467. #ifndef __STDC__
  2468.   enum tree_code code;
  2469.   tree tt;
  2470. #endif
  2471.   va_list p;
  2472.   register tree t;
  2473.   register int length;
  2474.   register int i;
  2475.  
  2476.   VA_START (p, tt);
  2477.  
  2478. #ifndef __STDC__
  2479.   code = va_arg (p, enum tree_code);
  2480.   tt = va_arg (p, tree);
  2481. #endif
  2482.  
  2483.   t = make_node (code);
  2484.   length = tree_code_length[(int) code];
  2485.   TREE_TYPE (t) = tt;
  2486.  
  2487.   if (length == 2)
  2488.     {
  2489.       /* This is equivalent to the loop below, but faster.  */
  2490.       register tree arg0 = va_arg (p, tree);
  2491.       register tree arg1 = va_arg (p, tree);
  2492.       TREE_OPERAND (t, 0) = arg0;
  2493.       TREE_OPERAND (t, 1) = arg1;
  2494.       if ((arg0 && TREE_SIDE_EFFECTS (arg0))
  2495.       || (arg1 && TREE_SIDE_EFFECTS (arg1)))
  2496.     TREE_SIDE_EFFECTS (t) = 1;
  2497.       TREE_RAISES (t)
  2498.     = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
  2499.     }
  2500.   else if (length == 1)
  2501.     {
  2502.       register tree arg0 = va_arg (p, tree);
  2503.  
  2504.       /* Call build1 for this!  */
  2505.       if (TREE_CODE_CLASS (code) != 's')
  2506.     abort ();
  2507.       TREE_OPERAND (t, 0) = arg0;
  2508.       if (arg0 && TREE_SIDE_EFFECTS (arg0))
  2509.     TREE_SIDE_EFFECTS (t) = 1;
  2510.       TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
  2511.     }
  2512.   else
  2513.     {
  2514.       for (i = 0; i < length; i++)
  2515.     {
  2516.       register tree operand = va_arg (p, tree);
  2517.       TREE_OPERAND (t, i) = operand;
  2518.       if (operand)
  2519.         {
  2520.           if (TREE_SIDE_EFFECTS (operand))
  2521.         TREE_SIDE_EFFECTS (t) = 1;
  2522.           if (TREE_RAISES (operand))
  2523.         TREE_RAISES (t) = 1;
  2524.         }
  2525.     }
  2526.     }
  2527.   va_end (p);
  2528.   return t;
  2529. }
  2530.  
  2531. /* Same as above, but only builds for unary operators.
  2532.    Saves lions share of calls to `build'; cuts down use
  2533.    of varargs, which is expensive for RISC machines.  */
  2534. tree
  2535. build1 (code, type, node)
  2536.      enum tree_code code;
  2537.      tree type;
  2538.      tree node;
  2539. {
  2540.   register struct obstack *obstack = current_obstack;
  2541.   register int i, length;
  2542.   register tree_node_kind kind;
  2543.   register tree t;
  2544.  
  2545. #ifdef GATHER_STATISTICS
  2546.   if (TREE_CODE_CLASS (code) == 'r')
  2547.     kind = r_kind;
  2548.   else
  2549.     kind = e_kind;
  2550. #endif
  2551.  
  2552.   obstack = expression_obstack;
  2553.   length = sizeof (struct tree_exp);
  2554.  
  2555.   t = (tree) obstack_alloc (obstack, length);
  2556.  
  2557. #ifdef GATHER_STATISTICS
  2558.   tree_node_counts[(int)kind]++;
  2559.   tree_node_sizes[(int)kind] += length;
  2560. #endif
  2561.  
  2562.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  2563.     ((int *) t)[i] = 0;
  2564.  
  2565.   TREE_TYPE (t) = type;
  2566.   TREE_SET_CODE (t, code);
  2567.  
  2568.   if (obstack == &permanent_obstack)
  2569.     TREE_PERMANENT (t) = 1;
  2570.  
  2571.   TREE_OPERAND (t, 0) = node;
  2572.   if (node)
  2573.     {
  2574.       if (TREE_SIDE_EFFECTS (node))
  2575.     TREE_SIDE_EFFECTS (t) = 1;
  2576.       if (TREE_RAISES (node))
  2577.     TREE_RAISES (t) = 1;
  2578.     }
  2579.  
  2580.   return t;
  2581. }
  2582.  
  2583. /* Similar except don't specify the TREE_TYPE
  2584.    and leave the TREE_SIDE_EFFECTS as 0.
  2585.    It is permissible for arguments to be null,
  2586.    or even garbage if their values do not matter.  */
  2587.  
  2588. tree
  2589. build_nt VPROTO((enum tree_code code, ...))
  2590. {
  2591. #ifndef __STDC__
  2592.   enum tree_code code;
  2593. #endif
  2594.   va_list p;
  2595.   register tree t;
  2596.   register int length;
  2597.   register int i;
  2598.  
  2599.   VA_START (p, code);
  2600.  
  2601. #ifndef __STDC__
  2602.   code = va_arg (p, enum tree_code);
  2603. #endif
  2604.  
  2605.   t = make_node (code);
  2606.   length = tree_code_length[(int) code];
  2607.  
  2608.   for (i = 0; i < length; i++)
  2609.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2610.  
  2611.   va_end (p);
  2612.   return t;
  2613. }
  2614.  
  2615. /* Similar to `build_nt', except we build
  2616.    on the temp_decl_obstack, regardless.  */
  2617.  
  2618. tree
  2619. build_parse_node VPROTO((enum tree_code code, ...))
  2620. {
  2621. #ifndef __STDC__
  2622.   enum tree_code code;
  2623. #endif
  2624.   register struct obstack *ambient_obstack = expression_obstack;
  2625.   va_list p;
  2626.   register tree t;
  2627.   register int length;
  2628.   register int i;
  2629.  
  2630.   VA_START (p, code);
  2631.  
  2632. #ifndef __STDC__
  2633.   code = va_arg (p, enum tree_code);
  2634. #endif
  2635.  
  2636.   expression_obstack = &temp_decl_obstack;
  2637.  
  2638.   t = make_node (code);
  2639.   length = tree_code_length[(int) code];
  2640.  
  2641.   for (i = 0; i < length; i++)
  2642.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2643.  
  2644.   va_end (p);
  2645.   expression_obstack = ambient_obstack;
  2646.   return t;
  2647. }
  2648.  
  2649. #if 0
  2650. /* Commented out because this wants to be done very
  2651.    differently.  See cp-lex.c.  */
  2652. tree
  2653. build_op_identifier (op1, op2)
  2654.      tree op1, op2;
  2655. {
  2656.   register tree t = make_node (OP_IDENTIFIER);
  2657.   TREE_PURPOSE (t) = op1;
  2658.   TREE_VALUE (t) = op2;
  2659.   return t;
  2660. }
  2661. #endif
  2662.  
  2663. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  2664.    We do NOT enter this node in any sort of symbol table.
  2665.  
  2666.    layout_decl is used to set up the decl's storage layout.
  2667.    Other slots are initialized to 0 or null pointers.  */
  2668.  
  2669. tree
  2670. build_decl (code, name, type)
  2671.      enum tree_code code;
  2672.      tree name, type;
  2673. {
  2674.   register tree t;
  2675.  
  2676.   t = make_node (code);
  2677.  
  2678. /*  if (type == error_mark_node)
  2679.     type = integer_type_node; */
  2680. /* That is not done, deliberately, so that having error_mark_node
  2681.    as the type can suppress useless errors in the use of this variable.  */
  2682.  
  2683.   DECL_NAME (t) = name;
  2684.   DECL_ASSEMBLER_NAME (t) = name;
  2685.   TREE_TYPE (t) = type;
  2686.  
  2687.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  2688.     layout_decl (t, 0);
  2689.   else if (code == FUNCTION_DECL)
  2690.     DECL_MODE (t) = FUNCTION_MODE;
  2691.  
  2692.   return t;
  2693. }
  2694.  
  2695. /* BLOCK nodes are used to represent the structure of binding contours
  2696.    and declarations, once those contours have been exited and their contents
  2697.    compiled.  This information is used for outputting debugging info.  */
  2698.  
  2699. tree
  2700. build_block (vars, tags, subblocks, supercontext, chain)
  2701.      tree vars, tags, subblocks, supercontext, chain;
  2702. {
  2703.   register tree block = make_node (BLOCK);
  2704.   BLOCK_VARS (block) = vars;
  2705.   BLOCK_TYPE_TAGS (block) = tags;
  2706.   BLOCK_SUBBLOCKS (block) = subblocks;
  2707.   BLOCK_SUPERCONTEXT (block) = supercontext;
  2708.   BLOCK_CHAIN (block) = chain;
  2709.   return block;
  2710. }
  2711.  
  2712. /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
  2713.    is ATTRIBUTE.
  2714.  
  2715.    Such modified types already made are recorded so that duplicates
  2716.    are not made. */
  2717.  
  2718. tree
  2719. build_type_attribute_variant (ttype, attribute)
  2720.      tree ttype, attribute;
  2721. {
  2722.   if ( ! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
  2723.     {
  2724.       register int hashcode;
  2725.       register struct obstack *ambient_obstack = current_obstack;
  2726.       tree ntype;
  2727.  
  2728.       if (ambient_obstack != &permanent_obstack)
  2729.         current_obstack = TYPE_OBSTACK (ttype);
  2730.  
  2731.       ntype = copy_node (ttype);
  2732.       current_obstack = ambient_obstack;
  2733.  
  2734.       TYPE_POINTER_TO (ntype) = 0;
  2735.       TYPE_REFERENCE_TO (ntype) = 0;
  2736.       TYPE_ATTRIBUTES (ntype) = attribute;
  2737.  
  2738.       /* Create a new main variant of TYPE.  */
  2739.       TYPE_MAIN_VARIANT (ntype) = ntype;
  2740.       TYPE_NEXT_VARIANT (ntype) = 0;
  2741.       TYPE_READONLY (ntype) = TYPE_VOLATILE (ntype) = 0;
  2742.  
  2743.       hashcode = TYPE_HASH (TREE_CODE (ntype))
  2744.          + TYPE_HASH (TREE_TYPE (ntype))
  2745.          + type_hash_list (attribute);
  2746.  
  2747.       switch (TREE_CODE (ntype))
  2748.         {
  2749.       case FUNCTION_TYPE:
  2750.         hashcode += TYPE_HASH (TYPE_ARG_TYPES (ntype));
  2751.         break;
  2752.       case ARRAY_TYPE:
  2753.         hashcode += TYPE_HASH (TYPE_DOMAIN (ntype));
  2754.         break;
  2755.       case INTEGER_TYPE:
  2756.         hashcode += TYPE_HASH (TYPE_MAX_VALUE (ntype));
  2757.         break;
  2758.       case REAL_TYPE:
  2759.         hashcode += TYPE_HASH (TYPE_PRECISION (ntype));
  2760.         break;
  2761.         }
  2762.  
  2763.       ntype = type_hash_canon (hashcode, ntype);
  2764.       ttype = build_type_variant (ntype, TYPE_READONLY (ttype),
  2765.                   TYPE_VOLATILE (ttype));
  2766.     }
  2767.  
  2768.   return ttype;
  2769. }
  2770.  
  2771. /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
  2772.    and its TYPE_VOLATILE is VOLATILEP.
  2773.  
  2774.    Such variant types already made are recorded so that duplicates
  2775.    are not made.
  2776.  
  2777.    A variant types should never be used as the type of an expression.
  2778.    Always copy the variant information into the TREE_READONLY
  2779.    and TREE_THIS_VOLATILE of the expression, and then give the expression
  2780.    as its type the "main variant", the variant whose TYPE_READONLY
  2781.    and TYPE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  2782.    main variant.  */
  2783.  
  2784. tree
  2785. build_type_variant (type, constp, volatilep)
  2786.      tree type;
  2787.      int constp, volatilep;
  2788. {
  2789.   register tree t;
  2790.  
  2791.   /* Treat any nonzero argument as 1.  */
  2792.   constp = !!constp;
  2793.   volatilep = !!volatilep;
  2794.  
  2795.   /* If not generating auxiliary info, search the chain of variants to see
  2796.      if there is already one there just like the one we need to have.  If so,
  2797.      use that existing one.
  2798.  
  2799.      We don't do this in the case where we are generating aux info because
  2800.      in that case we want each typedef names to get it's own distinct type
  2801.      node, even if the type of this new typedef is the same as some other
  2802.      (existing) type.  */
  2803.  
  2804.   if (!flag_gen_aux_info)
  2805.     for (t = TYPE_MAIN_VARIANT(type); t; t = TYPE_NEXT_VARIANT (t))
  2806.       if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
  2807.         return t;
  2808.  
  2809.   /* We need a new one.  */
  2810.  
  2811.   t = build_type_copy (type);
  2812.   TYPE_READONLY (t) = constp;
  2813.   TYPE_VOLATILE (t) = volatilep;
  2814.  
  2815.   return t;
  2816. }
  2817.  
  2818. /* Give TYPE a new main variant: NEW_MAIN.
  2819.    This is the right thing to do only when something else
  2820.    about TYPE is modified in place.  */
  2821.  
  2822. tree
  2823. change_main_variant (type, new_main)
  2824.      tree type, new_main;
  2825. {
  2826.   tree t;
  2827.   tree omain = TYPE_MAIN_VARIANT (type);
  2828.  
  2829.   /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant.  */
  2830.   if (TYPE_NEXT_VARIANT (omain) == type)
  2831.     TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
  2832.   else
  2833.     for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
  2834.      t = TYPE_NEXT_VARIANT (t))
  2835.       if (TYPE_NEXT_VARIANT (t) == type)
  2836.     {
  2837.       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
  2838.       break;
  2839.     }
  2840.  
  2841.   TYPE_MAIN_VARIANT (type) = new_main;
  2842.   TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
  2843.   TYPE_NEXT_VARIANT (new_main) = type;
  2844. }
  2845.  
  2846. /* Create a new variant of TYPE, equivalent but distinct.
  2847.    This is so the caller can modify it.  */
  2848.  
  2849. tree
  2850. build_type_copy (type)
  2851.      tree type;
  2852. {
  2853.   register tree t, m = TYPE_MAIN_VARIANT (type);
  2854.   register struct obstack *ambient_obstack = current_obstack;
  2855.  
  2856.   current_obstack = TYPE_OBSTACK (type);
  2857.   t = copy_node (type);
  2858.   current_obstack = ambient_obstack;
  2859.  
  2860.   TYPE_POINTER_TO (t) = 0;
  2861.   TYPE_REFERENCE_TO (t) = 0;
  2862.  
  2863.   /* Add this type to the chain of variants of TYPE.  */
  2864.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  2865.   TYPE_NEXT_VARIANT (m) = t;
  2866.  
  2867.   return t;
  2868. }
  2869.  
  2870. /* Hashing of types so that we don't make duplicates.
  2871.    The entry point is `type_hash_canon'.  */
  2872.  
  2873. /* Each hash table slot is a bucket containing a chain
  2874.    of these structures.  */
  2875.  
  2876. struct type_hash
  2877. {
  2878.   struct type_hash *next;    /* Next structure in the bucket.  */
  2879.   int hashcode;            /* Hash code of this type.  */
  2880.   tree type;            /* The type recorded here.  */
  2881. };
  2882.  
  2883. /* Now here is the hash table.  When recording a type, it is added
  2884.    to the slot whose index is the hash code mod the table size.
  2885.    Note that the hash table is used for several kinds of types
  2886.    (function types, array types and array index range types, for now).
  2887.    While all these live in the same table, they are completely independent,
  2888.    and the hash code is computed differently for each of these.  */
  2889.  
  2890. #define TYPE_HASH_SIZE 59
  2891. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  2892.  
  2893. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  2894.    with types in the TREE_VALUE slots), by adding the hash codes
  2895.    of the individual types.  */
  2896.  
  2897. int
  2898. type_hash_list (list)
  2899.      tree list;
  2900. {
  2901.   register int hashcode;
  2902.   register tree tail;
  2903.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  2904.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  2905.   return hashcode;
  2906. }
  2907.  
  2908. /* Look in the type hash table for a type isomorphic to TYPE.
  2909.    If one is found, return it.  Otherwise return 0.  */
  2910.  
  2911. tree
  2912. type_hash_lookup (hashcode, type)
  2913.      int hashcode;
  2914.      tree type;
  2915. {
  2916.   register struct type_hash *h;
  2917.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  2918.     if (h->hashcode == hashcode
  2919.     && TREE_CODE (h->type) == TREE_CODE (type)
  2920.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  2921.         && attribute_list_equal (TYPE_ATTRIBUTES (h->type),
  2922.                    TYPE_ATTRIBUTES (type))
  2923.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  2924.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  2925.                    TYPE_MAX_VALUE (type)))
  2926.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  2927.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  2928.                    TYPE_MIN_VALUE (type)))
  2929.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  2930.         || (TYPE_DOMAIN (h->type)
  2931.         && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  2932.         && TYPE_DOMAIN (type)
  2933.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  2934.         && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
  2935.       return h->type;
  2936.   return 0;
  2937. }
  2938.  
  2939. /* Add an entry to the type-hash-table
  2940.    for a type TYPE whose hash code is HASHCODE.  */
  2941.  
  2942. void
  2943. type_hash_add (hashcode, type)
  2944.      int hashcode;
  2945.      tree type;
  2946. {
  2947.   register struct type_hash *h;
  2948.  
  2949.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  2950.   h->hashcode = hashcode;
  2951.   h->type = type;
  2952.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  2953.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  2954. }
  2955.  
  2956. /* Given TYPE, and HASHCODE its hash code, return the canonical
  2957.    object for an identical type if one already exists.
  2958.    Otherwise, return TYPE, and record it as the canonical object
  2959.    if it is a permanent object.
  2960.  
  2961.    To use this function, first create a type of the sort you want.
  2962.    Then compute its hash code from the fields of the type that
  2963.    make it different from other similar types.
  2964.    Then call this function and use the value.
  2965.    This function frees the type you pass in if it is a duplicate.  */
  2966.  
  2967. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  2968. int debug_no_type_hash = 0;
  2969.  
  2970. tree
  2971. type_hash_canon (hashcode, type)
  2972.      int hashcode;
  2973.      tree type;
  2974. {
  2975.   tree t1;
  2976.  
  2977.   if (debug_no_type_hash)
  2978.     return type;
  2979.  
  2980.   t1 = type_hash_lookup (hashcode, type);
  2981.   if (t1 != 0)
  2982.     {
  2983.       obstack_free (TYPE_OBSTACK (type), type);
  2984. #ifdef GATHER_STATISTICS
  2985.       tree_node_counts[(int)t_kind]--;
  2986.       tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
  2987. #endif
  2988.       return t1;
  2989.     }
  2990.  
  2991.   /* If this is a permanent type, record it for later reuse.  */
  2992.   if (TREE_PERMANENT (type))
  2993.     type_hash_add (hashcode, type);
  2994.  
  2995.   return type;
  2996. }
  2997.  
  2998. /* Given two lists of attributes, return true if list l2 is
  2999.    equivalent to l1.  */
  3000.  
  3001. int
  3002. attribute_list_equal (l1, l2)
  3003.      tree l1, l2;
  3004. {
  3005.    return attribute_list_contained (l1, l2)
  3006.       && attribute_list_contained (l2, l1);
  3007. }
  3008.  
  3009. /* Given two lists of attributes, return true if list l2 is
  3010.    completely contained within l1.  */
  3011.  
  3012. int
  3013. attribute_list_contained (l1, l2)
  3014.      tree l1, l2;
  3015. {
  3016.   register tree t1, t2;
  3017.  
  3018.   /* First check the obvious, maybe the lists are identical.  */
  3019.   if (l1 == l2)
  3020.      return 1;
  3021.  
  3022.   /* Then check the obvious, maybe the lists are similar.  */
  3023.   for (t1 = l1, t2 = l2;
  3024.        t1 && t2
  3025.         && TREE_VALUE (t1) == TREE_VALUE (t2);
  3026.        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
  3027.  
  3028.   /* Maybe the lists are equal.  */
  3029.   if (t1 == 0 && t2 == 0)
  3030.      return 1;
  3031.  
  3032.   for (; t2; t2 = TREE_CHAIN (t2))
  3033.      if (!value_member (l1, t2))
  3034.     return 0;
  3035.   return 1;
  3036. }
  3037.  
  3038. /* Given two lists of types
  3039.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  3040.    return 1 if the lists contain the same types in the same order.
  3041.    Also, the TREE_PURPOSEs must match.  */
  3042.  
  3043. int
  3044. type_list_equal (l1, l2)
  3045.      tree l1, l2;
  3046. {
  3047.   register tree t1, t2;
  3048.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  3049.     {
  3050.       if (TREE_VALUE (t1) != TREE_VALUE (t2))
  3051.     return 0;
  3052.       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
  3053.     {
  3054.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  3055.       if (cmp < 0)
  3056.         abort ();
  3057.       if (cmp == 0)
  3058.         return 0;
  3059.     }
  3060.     }
  3061.  
  3062.   return t1 == t2;
  3063. }
  3064.  
  3065. /* Nonzero if integer constants T1 and T2
  3066.    represent the same constant value.  */
  3067.  
  3068. int
  3069. tree_int_cst_equal (t1, t2)
  3070.      tree t1, t2;
  3071. {
  3072.   if (t1 == t2)
  3073.     return 1;
  3074.   if (t1 == 0 || t2 == 0)
  3075.     return 0;
  3076.   if (TREE_CODE (t1) == INTEGER_CST
  3077.       && TREE_CODE (t2) == INTEGER_CST
  3078.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3079.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  3080.     return 1;
  3081.   return 0;
  3082. }
  3083.  
  3084. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  3085.    The precise way of comparison depends on their data type.  */
  3086.  
  3087. int
  3088. tree_int_cst_lt (t1, t2)
  3089.      tree t1, t2;
  3090. {
  3091.   if (t1 == t2)
  3092.     return 0;
  3093.  
  3094.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  3095.     return INT_CST_LT (t1, t2);
  3096.   return INT_CST_LT_UNSIGNED (t1, t2);
  3097. }
  3098.  
  3099. /* Return an indication of the sign of the integer constant T.
  3100.    The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
  3101.    Note that -1 will never be returned it T's type is unsigned.  */
  3102.  
  3103. int
  3104. tree_int_cst_sgn (t)
  3105.      tree t;
  3106. {
  3107.   if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
  3108.     return 0;
  3109.   else if (TREE_UNSIGNED (TREE_TYPE (t)))
  3110.     return 1;
  3111.   else if (TREE_INT_CST_HIGH (t) < 0)
  3112.     return -1;
  3113.   else
  3114.     return 1;
  3115. }
  3116.  
  3117. /* Compare two constructor-element-type constants.  */
  3118. int
  3119. simple_cst_list_equal (l1, l2)
  3120.      tree l1, l2;
  3121. {
  3122.   while (l1 != NULL_TREE && l2 != NULL_TREE)
  3123.     {
  3124.       int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
  3125.       if (cmp < 0)
  3126.     abort ();
  3127.       if (cmp == 0)
  3128.     return 0;
  3129.       l1 = TREE_CHAIN (l1);
  3130.       l2 = TREE_CHAIN (l2);
  3131.     }
  3132.   return (l1 == l2);
  3133. }
  3134.  
  3135. /* Return truthvalue of whether T1 is the same tree structure as T2.
  3136.    Return 1 if they are the same.
  3137.    Return 0 if they are understandably different.
  3138.    Return -1 if either contains tree structure not understood by
  3139.    this function.  */
  3140.  
  3141. int
  3142. simple_cst_equal (t1, t2)
  3143.      tree t1, t2;
  3144. {
  3145.   register enum tree_code code1, code2;
  3146.   int cmp;
  3147.  
  3148.   if (t1 == t2)
  3149.     return 1;
  3150.   if (t1 == 0 || t2 == 0)
  3151.     return 0;
  3152.  
  3153.   code1 = TREE_CODE (t1);
  3154.   code2 = TREE_CODE (t2);
  3155.  
  3156.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
  3157.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
  3158.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3159.     else
  3160.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  3161.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
  3162.        || code2 == NON_LVALUE_EXPR)
  3163.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  3164.  
  3165.   if (code1 != code2)
  3166.     return 0;
  3167.  
  3168.   switch (code1)
  3169.     {
  3170.     case INTEGER_CST:
  3171.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  3172.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  3173.  
  3174.     case REAL_CST:
  3175.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  3176.  
  3177.     case STRING_CST:
  3178.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  3179.     && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
  3180.           TREE_STRING_LENGTH (t1));
  3181.  
  3182.     case CONSTRUCTOR:
  3183.       abort ();
  3184.  
  3185.     case SAVE_EXPR:
  3186.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3187.  
  3188.     case CALL_EXPR:
  3189.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3190.       if (cmp <= 0)
  3191.     return cmp;
  3192.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3193.  
  3194.     case TARGET_EXPR:
  3195.       /* Special case: if either target is an unallocated VAR_DECL,
  3196.      it means that it's going to be unified with whatever the
  3197.      TARGET_EXPR is really supposed to initialize, so treat it
  3198.      as being equivalent to anything.  */
  3199.       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
  3200.        && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
  3201.        && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
  3202.       || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
  3203.           && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
  3204.           && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
  3205.     cmp = 1;
  3206.       else
  3207.     cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3208.       if (cmp <= 0)
  3209.     return cmp;
  3210.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  3211.  
  3212.     case WITH_CLEANUP_EXPR:
  3213.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3214.       if (cmp <= 0)
  3215.     return cmp;
  3216.       return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
  3217.  
  3218.     case COMPONENT_REF:
  3219.       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
  3220.     return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  3221.       return 0;
  3222.  
  3223.     case VAR_DECL:
  3224.     case PARM_DECL:
  3225.     case CONST_DECL:
  3226.     case FUNCTION_DECL:
  3227.       return 0;
  3228.     }
  3229.  
  3230.   /* This general rule works for most tree codes.
  3231.      All exceptions should be handled above.  */
  3232.  
  3233.   switch (TREE_CODE_CLASS (code1))
  3234.     {
  3235.       int i;
  3236.     case '1':
  3237.     case '2':
  3238.     case '<':
  3239.     case 'e':
  3240.     case 'r':
  3241.     case 's':
  3242.       cmp = 1;
  3243.       for (i=0; i<tree_code_length[(int) code1]; ++i)
  3244.     {
  3245.       cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
  3246.       if (cmp <= 0)
  3247.         return cmp;
  3248.     }
  3249.       return cmp;
  3250.     }
  3251.  
  3252.   return -1;
  3253. }
  3254.  
  3255. /* Constructors for pointer, array and function types.
  3256.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  3257.    constructed by language-dependent code, not here.)  */
  3258.  
  3259. /* Construct, lay out and return the type of pointers to TO_TYPE.
  3260.    If such a type has already been constructed, reuse it.  */
  3261.  
  3262. tree
  3263. build_pointer_type (to_type)
  3264.      tree to_type;
  3265. {
  3266.   register tree t = TYPE_POINTER_TO (to_type);
  3267.  
  3268.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3269.  
  3270.   if (t)
  3271.     return t;
  3272.  
  3273.   /* We need a new one.  Put this in the same obstack as TO_TYPE.   */
  3274.   push_obstacks (TYPE_OBSTACK (to_type), TYPE_OBSTACK (to_type));
  3275.   t = make_node (POINTER_TYPE);
  3276.   pop_obstacks ();
  3277.  
  3278.   TREE_TYPE (t) = to_type;
  3279.  
  3280.   /* Record this type as the pointer to TO_TYPE.  */
  3281.   TYPE_POINTER_TO (to_type) = t;
  3282.  
  3283.   /* Lay out the type.  This function has many callers that are concerned
  3284.      with expression-construction, and this simplifies them all.
  3285.      Also, it guarantees the TYPE_SIZE is in the same obstack as the type.  */
  3286.   layout_type (t);
  3287.  
  3288.   return t;
  3289. }
  3290.  
  3291. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  3292.    MAXVAL should be the maximum value in the domain
  3293.    (one less than the length of the array).  */
  3294.  
  3295. tree
  3296. build_index_type (maxval)
  3297.      tree maxval;
  3298. {
  3299.   register tree itype = make_node (INTEGER_TYPE);
  3300.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  3301.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  3302.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  3303.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  3304.   TYPE_MODE (itype) = TYPE_MODE (sizetype);
  3305.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  3306.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  3307.   if (TREE_CODE (maxval) == INTEGER_CST)
  3308.     {
  3309.       int maxint = (int) TREE_INT_CST_LOW (maxval);
  3310.       /* If the domain should be empty, make sure the maxval
  3311.      remains -1 and is not spoiled by truncation.  */
  3312.       if (INT_CST_LT (maxval, integer_zero_node))
  3313.     {
  3314.       TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
  3315.       TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
  3316.     }
  3317.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3318.     }
  3319.   else
  3320.     return itype;
  3321. }
  3322.  
  3323. /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
  3324.    ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
  3325.    low bound LOWVAL and high bound HIGHVAL.
  3326.    if TYPE==NULL_TREE, sizetype is used. */
  3327.  
  3328. tree
  3329. build_range_type (type, lowval, highval)
  3330.      tree type, lowval, highval;
  3331. {
  3332.   register tree itype = make_node (INTEGER_TYPE);
  3333.   TREE_TYPE (itype) = type;
  3334.   if (type == NULL_TREE)
  3335.     type = sizetype;
  3336.   TYPE_PRECISION (itype) = TYPE_PRECISION (type);
  3337.   TYPE_MIN_VALUE (itype) = convert (type, lowval);
  3338.   TYPE_MAX_VALUE (itype) = convert (type, highval);
  3339.   TYPE_MODE (itype) = TYPE_MODE (type);
  3340.   TYPE_SIZE (itype) = TYPE_SIZE (type);
  3341.   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
  3342.   if ((TREE_CODE (lowval) == INTEGER_CST)
  3343.       && (TREE_CODE (highval) == INTEGER_CST))
  3344.     {
  3345.       HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
  3346.       HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
  3347.       int maxint = (int) (highint - lowint);
  3348.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  3349.     }
  3350.   else
  3351.     return itype;
  3352. }
  3353.  
  3354. /* Just like build_index_type, but takes lowval and highval instead
  3355.    of just highval (maxval). */
  3356.  
  3357. tree
  3358. build_index_2_type (lowval,highval)
  3359.      tree lowval, highval;
  3360. {
  3361.   return build_range_type (NULL_TREE, lowval, highval);
  3362. }
  3363.  
  3364. /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
  3365.    Needed because when index types are not hashed, equal index types
  3366.    built at different times appear distinct, even though structurally,
  3367.    they are not.  */
  3368.  
  3369. int
  3370. index_type_equal (itype1, itype2)
  3371.      tree itype1, itype2;
  3372. {
  3373.   if (TREE_CODE (itype1) != TREE_CODE (itype2))
  3374.     return 0;
  3375.   if (TREE_CODE (itype1) == INTEGER_TYPE)
  3376.     {
  3377.       if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
  3378.       || TYPE_MODE (itype1) != TYPE_MODE (itype2)
  3379.       || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
  3380.       || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
  3381.     return 0;
  3382.       if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
  3383.       && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
  3384.     return 1;
  3385.     }
  3386.   return 0;
  3387. }
  3388.  
  3389. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  3390.    and number of elements specified by the range of values of INDEX_TYPE.
  3391.    If such a type has already been constructed, reuse it.  */
  3392.  
  3393. tree
  3394. build_array_type (elt_type, index_type)
  3395.      tree elt_type, index_type;
  3396. {
  3397.   register tree t;
  3398.   int hashcode;
  3399.  
  3400.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  3401.     {
  3402.       error ("arrays of functions are not meaningful");
  3403.       elt_type = integer_type_node;
  3404.     }
  3405.  
  3406.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  3407.   build_pointer_type (elt_type);
  3408.  
  3409.   /* Allocate the array after the pointer type,
  3410.      in case we free it in type_hash_canon.  */
  3411.   t = make_node (ARRAY_TYPE);
  3412.   TREE_TYPE (t) = elt_type;
  3413.   TYPE_DOMAIN (t) = index_type;
  3414.  
  3415.   if (index_type == 0)
  3416.     {
  3417.       return t;
  3418.     }
  3419.  
  3420.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  3421.   t = type_hash_canon (hashcode, t);
  3422.  
  3423. #if 0 /* This led to crashes, because it could put a temporary node
  3424.      on the TYPE_NEXT_VARIANT chain of a permanent one.  */
  3425.   /* The main variant of an array type should always
  3426.      be an array whose element type is the main variant.  */
  3427.   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
  3428.     change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
  3429.                           index_type));
  3430. #endif
  3431.  
  3432.   if (TYPE_SIZE (t) == 0)
  3433.     layout_type (t);
  3434.   return t;
  3435. }
  3436.  
  3437. /* Construct, lay out and return
  3438.    the type of functions returning type VALUE_TYPE
  3439.    given arguments of types ARG_TYPES.
  3440.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  3441.    are data type nodes for the arguments of the function.
  3442.    If such a type has already been constructed, reuse it.  */
  3443.  
  3444. tree
  3445. build_function_type (value_type, arg_types)
  3446.      tree value_type, arg_types;
  3447. {
  3448.   register tree t;
  3449.   int hashcode;
  3450.  
  3451.   if (TREE_CODE (value_type) == FUNCTION_TYPE)
  3452.     {
  3453.       error ("function return type cannot be function");
  3454.       value_type = integer_type_node;
  3455.     }
  3456.  
  3457.   /* Make a node of the sort we want.  */
  3458.   t = make_node (FUNCTION_TYPE);
  3459.   TREE_TYPE (t) = value_type;
  3460.   TYPE_ARG_TYPES (t) = arg_types;
  3461.  
  3462.   /* If we already have such a type, use the old one and free this one.  */
  3463.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  3464.   t = type_hash_canon (hashcode, t);
  3465.  
  3466.   if (TYPE_SIZE (t) == 0)
  3467.     layout_type (t);
  3468.   return t;
  3469. }
  3470.  
  3471. /* Build the node for the type of references-to-TO_TYPE.  */
  3472.  
  3473. tree
  3474. build_reference_type (to_type)
  3475.      tree to_type;
  3476. {
  3477.   register tree t = TYPE_REFERENCE_TO (to_type);
  3478.   register struct obstack *ambient_obstack = current_obstack;
  3479.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  3480.  
  3481.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  3482.  
  3483.   if (t)
  3484.     return t;
  3485.  
  3486.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  3487.   if (TREE_PERMANENT (to_type))
  3488.     {
  3489.       current_obstack = &permanent_obstack;
  3490.       saveable_obstack = &permanent_obstack;
  3491.     }
  3492.  
  3493.   t = make_node (REFERENCE_TYPE);
  3494.   TREE_TYPE (t) = to_type;
  3495.  
  3496.   /* Record this type as the pointer to TO_TYPE.  */
  3497.   TYPE_REFERENCE_TO (to_type) = t;
  3498.  
  3499.   layout_type (t);
  3500.  
  3501.   current_obstack = ambient_obstack;
  3502.   saveable_obstack = ambient_saveable_obstack;
  3503.   return t;
  3504. }
  3505.  
  3506. /* Construct, lay out and return the type of methods belonging to class
  3507.    BASETYPE and whose arguments and values are described by TYPE.
  3508.    If that type exists already, reuse it.
  3509.    TYPE must be a FUNCTION_TYPE node.  */
  3510.  
  3511. tree
  3512. build_method_type (basetype, type)
  3513.      tree basetype, type;
  3514. {
  3515.   register tree t;
  3516.   int hashcode;
  3517.  
  3518.   /* Make a node of the sort we want.  */
  3519.   t = make_node (METHOD_TYPE);
  3520.  
  3521.   if (TREE_CODE (type) != FUNCTION_TYPE)
  3522.     abort ();
  3523.  
  3524.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3525.   TREE_TYPE (t) = TREE_TYPE (type);
  3526.  
  3527.   /* The actual arglist for this function includes a "hidden" argument
  3528.      which is "this".  Put it into the list of argument types.  */
  3529.  
  3530.   TYPE_ARG_TYPES (t)
  3531.     = tree_cons (NULL_TREE,
  3532.          build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  3533.  
  3534.   /* If we already have such a type, use the old one and free this one.  */
  3535.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3536.   t = type_hash_canon (hashcode, t);
  3537.  
  3538.   if (TYPE_SIZE (t) == 0)
  3539.     layout_type (t);
  3540.  
  3541.   return t;
  3542. }
  3543.  
  3544. /* Construct, lay out and return the type of offsets to a value
  3545.    of type TYPE, within an object of type BASETYPE.
  3546.    If a suitable offset type exists already, reuse it.  */
  3547.  
  3548. tree
  3549. build_offset_type (basetype, type)
  3550.      tree basetype, type;
  3551. {
  3552.   register tree t;
  3553.   int hashcode;
  3554.  
  3555.   /* Make a node of the sort we want.  */
  3556.   t = make_node (OFFSET_TYPE);
  3557.  
  3558.   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  3559.   TREE_TYPE (t) = type;
  3560.  
  3561.   /* If we already have such a type, use the old one and free this one.  */
  3562.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  3563.   t = type_hash_canon (hashcode, t);
  3564.  
  3565.   if (TYPE_SIZE (t) == 0)
  3566.     layout_type (t);
  3567.  
  3568.   return t;
  3569. }
  3570.  
  3571. /* Create a complex type whose components are COMPONENT_TYPE.  */
  3572.  
  3573. tree
  3574. build_complex_type (component_type)
  3575.      tree component_type;
  3576. {
  3577.   register tree t;
  3578.   int hashcode;
  3579.  
  3580.   /* Make a node of the sort we want.  */
  3581.   t = make_node (COMPLEX_TYPE);
  3582.  
  3583.   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
  3584.   TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
  3585.   TYPE_READONLY (t) = TYPE_READONLY (component_type);
  3586.  
  3587.   /* If we already have such a type, use the old one and free this one.  */
  3588.   hashcode = TYPE_HASH (component_type);
  3589.   t = type_hash_canon (hashcode, t);
  3590.  
  3591.   if (TYPE_SIZE (t) == 0)
  3592.     layout_type (t);
  3593.  
  3594.   return t;
  3595. }
  3596.  
  3597. /* Return OP, stripped of any conversions to wider types as much as is safe.
  3598.    Converting the value back to OP's type makes a value equivalent to OP.
  3599.  
  3600.    If FOR_TYPE is nonzero, we return a value which, if converted to
  3601.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  3602.  
  3603.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  3604.    narrowest type that can hold the value, even if they don't exactly fit.
  3605.    Otherwise, bit-field references are changed to a narrower type
  3606.    only if they can be fetched directly from memory in that type.
  3607.  
  3608.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  3609.  
  3610.    There are some cases where the obvious value we could return
  3611.    would regenerate to OP if converted to OP's type, 
  3612.    but would not extend like OP to wider types.
  3613.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  3614.    For example, if OP is (unsigned short)(signed char)-1,
  3615.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  3616.    even though extending that to an unsigned short would regenerate OP,
  3617.    since the result of extending (signed char)-1 to (int)
  3618.    is different from (int) OP.  */
  3619.  
  3620. tree
  3621. get_unwidened (op, for_type)
  3622.      register tree op;
  3623.      tree for_type;
  3624. {
  3625.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  3626.   /* TYPE_PRECISION is safe in place of type_precision since
  3627.      pointer types are not allowed.  */
  3628.   register tree type = TREE_TYPE (op);
  3629.   register unsigned final_prec
  3630.     = TYPE_PRECISION (for_type != 0 ? for_type : type);
  3631.   register int uns
  3632.     = (for_type != 0 && for_type != type
  3633.        && final_prec > TYPE_PRECISION (type)
  3634.        && TREE_UNSIGNED (type));
  3635.   register tree win = op;
  3636.  
  3637.   while (TREE_CODE (op) == NOP_EXPR)
  3638.     {
  3639.       register int bitschange
  3640.     = TYPE_PRECISION (TREE_TYPE (op))
  3641.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3642.  
  3643.       /* Truncations are many-one so cannot be removed.
  3644.      Unless we are later going to truncate down even farther.  */
  3645.       if (bitschange < 0
  3646.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  3647.     break;
  3648.  
  3649.       /* See what's inside this conversion.  If we decide to strip it,
  3650.      we will set WIN.  */
  3651.       op = TREE_OPERAND (op, 0);
  3652.  
  3653.       /* If we have not stripped any zero-extensions (uns is 0),
  3654.      we can strip any kind of extension.
  3655.      If we have previously stripped a zero-extension,
  3656.      only zero-extensions can safely be stripped.
  3657.      Any extension can be stripped if the bits it would produce
  3658.      are all going to be discarded later by truncating to FOR_TYPE.  */
  3659.  
  3660.       if (bitschange > 0)
  3661.     {
  3662.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  3663.         win = op;
  3664.       /* TREE_UNSIGNED says whether this is a zero-extension.
  3665.          Let's avoid computing it if it does not affect WIN
  3666.          and if UNS will not be needed again.  */
  3667.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  3668.           && TREE_UNSIGNED (TREE_TYPE (op)))
  3669.         {
  3670.           uns = 1;
  3671.           win = op;
  3672.         }
  3673.     }
  3674.     }
  3675.  
  3676.   if (TREE_CODE (op) == COMPONENT_REF
  3677.       /* Since type_for_size always gives an integer type.  */
  3678.       && TREE_CODE (type) != REAL_TYPE)
  3679.     {
  3680.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3681.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  3682.  
  3683.       /* We can get this structure field in the narrowest type it fits in.
  3684.      If FOR_TYPE is 0, do this only for a field that matches the
  3685.      narrower type exactly and is aligned for it
  3686.      The resulting extension to its nominal type (a fullword type)
  3687.      must fit the same conditions as for other extensions.  */
  3688.  
  3689.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3690.       && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
  3691.       && (! uns || final_prec <= innerprec
  3692.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3693.       && type != 0)
  3694.     {
  3695.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3696.                TREE_OPERAND (op, 1));
  3697.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3698.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3699.       TREE_RAISES (win) = TREE_RAISES (op);
  3700.     }
  3701.     }
  3702.   return win;
  3703. }
  3704.  
  3705. /* Return OP or a simpler expression for a narrower value
  3706.    which can be sign-extended or zero-extended to give back OP.
  3707.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  3708.    or 0 if the value should be sign-extended.  */
  3709.  
  3710. tree
  3711. get_narrower (op, unsignedp_ptr)
  3712.      register tree op;
  3713.      int *unsignedp_ptr;
  3714. {
  3715.   register int uns = 0;
  3716.   int first = 1;
  3717.   register tree win = op;
  3718.  
  3719.   while (TREE_CODE (op) == NOP_EXPR)
  3720.     {
  3721.       register int bitschange
  3722.     = TYPE_PRECISION (TREE_TYPE (op))
  3723.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3724.  
  3725.       /* Truncations are many-one so cannot be removed.  */
  3726.       if (bitschange < 0)
  3727.     break;
  3728.  
  3729.       /* See what's inside this conversion.  If we decide to strip it,
  3730.      we will set WIN.  */
  3731.       op = TREE_OPERAND (op, 0);
  3732.  
  3733.       if (bitschange > 0)
  3734.     {
  3735.       /* An extension: the outermost one can be stripped,
  3736.          but remember whether it is zero or sign extension.  */
  3737.       if (first)
  3738.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  3739.       /* Otherwise, if a sign extension has been stripped,
  3740.          only sign extensions can now be stripped;
  3741.          if a zero extension has been stripped, only zero-extensions.  */
  3742.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  3743.         break;
  3744.       first = 0;
  3745.     }
  3746.       else /* bitschange == 0 */
  3747.     {
  3748.       /* A change in nominal type can always be stripped, but we must
  3749.          preserve the unsignedness.  */
  3750.       if (first)
  3751.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  3752.       first = 0;
  3753.     }
  3754.  
  3755.       win = op;
  3756.     }
  3757.  
  3758.   if (TREE_CODE (op) == COMPONENT_REF
  3759.       /* Since type_for_size always gives an integer type.  */
  3760.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  3761.     {
  3762.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3763.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  3764.  
  3765.       /* We can get this structure field in a narrower type that fits it,
  3766.      but the resulting extension to its nominal type (a fullword type)
  3767.      must satisfy the same conditions as for other extensions.
  3768.  
  3769.      Do this only for fields that are aligned (not bit-fields),
  3770.      because when bit-field insns will be used there is no
  3771.      advantage in doing this.  */
  3772.  
  3773.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3774.       && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
  3775.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3776.       && type != 0)
  3777.     {
  3778.       if (first)
  3779.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  3780.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3781.                TREE_OPERAND (op, 1));
  3782.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3783.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3784.       TREE_RAISES (win) = TREE_RAISES (op);
  3785.     }
  3786.     }
  3787.   *unsignedp_ptr = uns;
  3788.   return win;
  3789. }
  3790.  
  3791. /* Return the precision of a type, for arithmetic purposes.
  3792.    Supports all types on which arithmetic is possible
  3793.    (including pointer types).
  3794.    It's not clear yet what will be right for complex types.  */
  3795.  
  3796. int
  3797. type_precision (type)
  3798.      register tree type;
  3799. {
  3800.   return ((TREE_CODE (type) == INTEGER_TYPE
  3801.        || TREE_CODE (type) == ENUMERAL_TYPE
  3802.        || TREE_CODE (type) == REAL_TYPE)
  3803.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  3804. }
  3805.  
  3806. /* Nonzero if integer constant C has a value that is permissible
  3807.    for type TYPE (an INTEGER_TYPE).  */
  3808.  
  3809. int
  3810. int_fits_type_p (c, type)
  3811.      tree c, type;
  3812. {
  3813.   if (TREE_UNSIGNED (type))
  3814.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  3815.            && INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c))
  3816.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  3817.           && INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))));
  3818.   else
  3819.     return (! (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
  3820.            && INT_CST_LT (TYPE_MAX_VALUE (type), c))
  3821.         && ! (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
  3822.           && INT_CST_LT (c, TYPE_MIN_VALUE (type))));
  3823. }
  3824.  
  3825. /* Return the innermost context enclosing DECL that is
  3826.    a FUNCTION_DECL, or zero if none.  */
  3827.  
  3828. tree
  3829. decl_function_context (decl)
  3830.      tree decl;
  3831. {
  3832.   tree context;
  3833.  
  3834.   if (TREE_CODE (decl) == ERROR_MARK)
  3835.     return 0;
  3836.  
  3837.   if (TREE_CODE (decl) == SAVE_EXPR)
  3838.     context = SAVE_EXPR_CONTEXT (decl);
  3839.   else
  3840.     context = DECL_CONTEXT (decl);
  3841.  
  3842.   while (context && TREE_CODE (context) != FUNCTION_DECL)
  3843.     {
  3844.       if (TREE_CODE (context) == RECORD_TYPE
  3845.       || TREE_CODE (context) == UNION_TYPE)
  3846.     context = TYPE_CONTEXT (context);
  3847.       else if (TREE_CODE (context) == TYPE_DECL)
  3848.     context = DECL_CONTEXT (context);
  3849.       else if (TREE_CODE (context) == BLOCK)
  3850.     context = BLOCK_SUPERCONTEXT (context);
  3851.       else
  3852.     /* Unhandled CONTEXT !?  */
  3853.     abort ();
  3854.     }
  3855.  
  3856.   return context;
  3857. }
  3858.  
  3859. /* Return the innermost context enclosing DECL that is
  3860.    a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
  3861.    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
  3862.  
  3863. tree
  3864. decl_type_context (decl)
  3865.      tree decl;
  3866. {
  3867.   tree context = DECL_CONTEXT (decl);
  3868.  
  3869.   while (context)
  3870.     {
  3871.       if (TREE_CODE (context) == RECORD_TYPE
  3872.       || TREE_CODE (context) == UNION_TYPE
  3873.       || TREE_CODE (context) == QUAL_UNION_TYPE)
  3874.     return context;
  3875.       if (TREE_CODE (context) == TYPE_DECL
  3876.       || TREE_CODE (context) == FUNCTION_DECL)
  3877.     context = DECL_CONTEXT (context);
  3878.       else if (TREE_CODE (context) == BLOCK)
  3879.     context = BLOCK_SUPERCONTEXT (context);
  3880.       else
  3881.     /* Unhandled CONTEXT!?  */
  3882.     abort ();
  3883.     }
  3884.   return NULL_TREE;
  3885. }
  3886.  
  3887. void
  3888. print_obstack_statistics (str, o)
  3889.      char *str;
  3890.      struct obstack *o;
  3891. {
  3892.   struct _obstack_chunk *chunk = o->chunk;
  3893.   int n_chunks = 0;
  3894.   int n_alloc = 0;
  3895.  
  3896.   while (chunk)
  3897.     {
  3898.       n_chunks += 1;
  3899.       n_alloc += chunk->limit - &chunk->contents[0];
  3900.       chunk = chunk->prev;
  3901.     }
  3902.   fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
  3903.        str, n_alloc, n_chunks);
  3904. }
  3905. void
  3906. dump_tree_statistics ()
  3907. {
  3908.   int i;
  3909.   int total_nodes, total_bytes;
  3910.  
  3911.   fprintf (stderr, "\n??? tree nodes created\n\n");
  3912. #ifdef GATHER_STATISTICS
  3913.   fprintf (stderr, "Kind                  Nodes     Bytes\n");
  3914.   fprintf (stderr, "-------------------------------------\n");
  3915.   total_nodes = total_bytes = 0;
  3916.   for (i = 0; i < (int) all_kinds; i++)
  3917.     {
  3918.       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
  3919.            tree_node_counts[i], tree_node_sizes[i]);
  3920.       total_nodes += tree_node_counts[i];
  3921.       total_bytes += tree_node_sizes[i];
  3922.     }
  3923.   fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);
  3924.   fprintf (stderr, "-------------------------------------\n");
  3925.   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
  3926.   fprintf (stderr, "-------------------------------------\n");
  3927. #else
  3928.   fprintf (stderr, "(No per-node statistics)\n");
  3929. #endif
  3930.   print_lang_statistics ();
  3931. }
  3932.  
  3933. #define FILE_FUNCTION_PREFIX_LEN 9
  3934.  
  3935. #ifndef NO_DOLLAR_IN_LABEL
  3936. #define FILE_FUNCTION_FORMAT "_GLOBAL_$D$%s"
  3937. #else /* NO_DOLLAR_IN_LABEL */
  3938. #ifndef NO_DOT_IN_LABEL
  3939. #define FILE_FUNCTION_FORMAT "_GLOBAL_.D.%s"
  3940. #else /* NO_DOT_IN_LABEL */
  3941. #define FILE_FUNCTION_FORMAT "_GLOBAL__D_%s"
  3942. #endif    /* NO_DOT_IN_LABEL */
  3943. #endif    /* NO_DOLLAR_IN_LABEL */
  3944.  
  3945. extern char * first_global_object_name;
  3946.  
  3947. /* If KIND=='I', return a suitable global initializer (constructor) name.
  3948.    If KIND=='D', return a suitable global clean-up (destructor) name. */
  3949.  
  3950. tree
  3951. get_file_function_name (kind)
  3952.      int kind;
  3953. {
  3954.   char *buf;
  3955.   register char *p;
  3956.  
  3957.   if (first_global_object_name)
  3958.     p = first_global_object_name;
  3959.   else if (main_input_filename)
  3960.     p = main_input_filename;
  3961.   else
  3962.     p = input_filename;
  3963.  
  3964.   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p));
  3965.  
  3966.   /* Set up the name of the file-level functions we may need.  */
  3967.   /* Use a global object (which is already required to be unique over
  3968.      the program) rather than the file name (which imposes extra
  3969.      constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */
  3970.   sprintf (buf, FILE_FUNCTION_FORMAT, p);
  3971.  
  3972.   /* Don't need to pull wierd characters out of global names.  */
  3973.   if (p != first_global_object_name)
  3974.     {
  3975.       for (p = buf+11; *p; p++)
  3976.     if (! ((*p >= '0' && *p <= '9')
  3977. #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
  3978. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  3979.            || *p == '.'
  3980. #endif
  3981. #endif
  3982. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  3983.            || *p == '$'
  3984. #endif
  3985. #ifndef NO_DOT_IN_LABEL        /* this for `.'; unlikely, but... */
  3986.            || *p == '.'
  3987. #endif
  3988.            || (*p >= 'A' && *p <= 'Z')
  3989.            || (*p >= 'a' && *p <= 'z')))
  3990.       *p = '_';
  3991.     }
  3992.  
  3993.   buf[FILE_FUNCTION_PREFIX_LEN] = kind;
  3994.  
  3995.   return get_identifier (buf);
  3996. }
  3997.